I am getting some confusing warnings when building a backend Node server with Webpack. I want to use Webpack to build my backend primarily for two reasons:
- Webpack creates a single executable file, which is easier to deploy
- Webpack includes all of my app's dependencies, so I can deploy my app to any compatible Node environment without needing to install dependencies first
Here are the warnings I'm getting:
WARNING in ./~/ws/lib/BufferUtil.js Module not found: Error: Can't resolve 'bufferutil' in .../node_modules/ws/lib @ ./~/ws/lib/BufferUtil.js 35:21-42 @ ./~/ws/lib/Receiver.js @ ./~/ws/index.js @ ./src/main.js WARNING in ./~/ws/lib/Validation.js Module not found: Error: Can't resolve 'utf-8-validate' in .../node_modules/ws/lib @ ./~/ws/lib/Validation.js 10:22-47 @ ./~/ws/lib/Receiver.js @ ./~/ws/index.js @ ./src/main.js WARNING in ./~/express/lib/view.js 80:29-41 Critical dependency: the request of a dependency is an expression
For the Critical dependency
warning, I've found a good example explaining the problem and some documentation on how to use the ContextReplacementPlugin, although it's still unclear to me how to apply it to this situation. It looks like the warning is being caused by line 80 in node_modules/express/lib/view.js
:
opts.engines[this.ext] = require(mod).__express
It is clear to me that the dependency cannot be resolved at build time, so how can I use the ContextReplacementPlugin to fix this dependency?
As for the Module not found
warnings in the ws
package, it's unclear to me what's going on. It looks like those dependencies exist in my global node_modules
, and maybe they're not being pulled in by Webpack. I've tried adding them to my project's devDependencies, but then I just get Critical dependency
warnings for them instead.
My application still runs after being built, so I suppose I could technically ignore the warnings, but I figure that these are widely used Node packages and Webpack is a popular build tool, so there must be a reasonable solution available.
Here are my dependencies in my package.json
:
"devDependencies": { "@types/cassandra-driver": "^0.8.10", "@types/express": "^4.0.35", "@types/uuid": "^2.0.29", "@types/ws": "0.0.40", "nodemon": "^1.11.0", "typescript": "^2.3.1", "webpack": "^2.5.1" }, "dependencies": { "cassandra-driver": "^3.2.1", "express": "^4.15.2", "uuid": "^3.0.1", "ws": "^2.3.1" }
And here's my webpack.config.js
:
const path = require('path'); module.exports = { entry: './src/main.js', output: { path: path.join(__dirname, 'dist'), filename: 'main.js' }, target: 'node', node: { __dirname: false, __filename: false } };
I like keeping things minimal if possible. Thanks for reading.
0 comments:
Post a Comment