4
votes

I am trying to build my prod webpack file and get 5-10 errors of "cannot resolve module" aws-sdk,child_process".

All of these errors are starting with the same path: "ERROR in (webpack)/~/watchpack/~/chokidar/~/fsevents/"

For example:

ERROR in (webpack)/~/watchpack/~/chokidar/~/fsevents/~/node-pre-gyp/lib/node-pre-gyp.js Module not found: Error: Cannot resolve 'file' or 'directory' ../package

ERROR in (webpack)/~/watchpack/~/chokidar/~/fsevents/~/node-pre-gyp/lib/info.js Module not found: Error: Cannot resolve module 'aws-sdk'

ERROR in (webpack)/~/watchpack/~/chokidar/~/fsevents/~/node-pre-gyp/lib/publish.js Module not found: Error: Cannot resolve module 'aws-sdk'

ERROR in (webpack)/~/watchpack/~/chokidar/~/fsevents/~/node-pre-gyp/lib/testbinary.js Module not found: Error: Cannot resolve module 'child_process'

ERROR in (webpack)/~/watchpack/~/chokidar/~/fsevents/~/forever-agent/index.js Module not found: Error: Cannot resolve module 'net'

Here are my dependencies from package.json:

"devDependencies": {

"babel-core": "^6.4.5",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"css-loader": "^0.25.0",
"file-loader": "^0.9.0",
"json-loader": "^0.5.4",
"node-sass": "^3.9.0",
"react": "^15.3.2",
"sass-loader": "^4.0.1",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.2",
"webpack-bundle-tracker": "0.0.93",
"webpack-dev-server": "^1.15.1"

}, "dependencies": {

"chart.js": "^1.1.1",
"jquery": "^2.2.0",
"material-ui": "^0.15.4",
"react-addons-css-transition-group": "^15.3.1",
"react-bootstrap": "^0.30.3",
"react-chartjs": "^0.8.0",
"react-dom": "^15.3.0",
"react-hot-loader": "^3.0.0-beta.3",
"react-redux": "^4.4.5",
"react-router": "^2.7.0",
"react-sortable-hoc": "0.0.8",
"react-tap-event-plugin": "^1.0.0",
"redux": "^3.6.0"

}

4
I'm having the same exact problem while not requiring aws-sdk myself. It also only happens on production environment. Did you find a solution ?Remi M

4 Answers

3
votes

I had the same problem, in fact you try to apply server module in the client side,to resolve this, in your webpack config client add the following code:

node: {
  fs: "empty",
  child_process : "empty",
  net : "empty",
}
2
votes

I had the same trouble while bundling the server. I was excluding node_modules from babel-loader but that's not enough to prevent webpack from bundling node_modules.

Here's the solution:

  • If you don't already have it, add target: 'node' to your webpack.config.js. This will exclude native node modules (path, fs, etc.) from being bundled.
  • Use webpack-node-externals to exclude node_modules.

Example:

    import nodeExternals from 'webpack-node-externals';
    ...
    const browserConfig = { ... };
    ...
    const serverConfig = {
        ...
        target: 'node',
        externals: [nodeExternals()],
        ...
    };
    export default [ browserConfig, serverConfig ];
2
votes

Well, I think you forgot --config use:

webpack --config webpack.config.js
0
votes

I had the same annoyance, but just adding --config solved my problem.

webpack --config webpack.config.js