3

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?

1 Answer 1

4

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.