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"
}
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",
}
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:
target: 'node'
to your webpack.config.js
. This will exclude native node modules (path, fs, etc.) from being bundled.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 ];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With