Reputation: 621
I'm trying to bundle an "express.js" script with esbuild using
esbuild index.js --bundle --platform=node --outfile=server.js
to run as a netlify/aws lambda function and seem always to get this warning:
> node_modules/express/lib/view.js: warning: This call to "require" will not be bundled because the argument is not a string literal
81 │ var fn = require(mod).__express
╵ ~~~~~~~
The function seems to run but I would like to find out what could be wrong and I couldn't find any hints online anywhere?
Upvotes: 3
Views: 1716
Reputation: 1041
The bundling process tries to produce a single file containing all of your code, but the warning is telling you that express contains some code that cannot be bundled into a single file. I'm not familiar with express but apparently this is also a problem with express and Webpack (see this question for an example).
Assuming you still keep the node_modules/express
folder around next to your bundle when you run the code, you could solve this problem with esbuild the same way the Webpack solution works: by marking the express
package as external. That would look like this:
esbuild index.js --bundle --platform=node --outfile=server.js --external:express
Upvotes: 3