我尝试将"express.js“脚本与esbuild捆绑在一起
esbuild index.js --bundle --platform=node --outfile=server.js要作为netlify/aws lambda函数运行,似乎总是收到以下警告:
> 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
╵ ~~~~~~~该函数似乎正在运行,但我想找出可能是哪里出了问题,并且我在网上找不到任何提示?
发布于 2020-11-26 08:43:59
绑定过程试图生成包含所有代码的单个文件,但警告告诉您express包含一些无法绑定到单个文件中的代码。我不熟悉express,但显然这也是express和Webpack的问题(参见this question的例子)。
假设您在运行代码时仍然将node_modules/express文件夹放在包的旁边,那么您可以使用esbuild以与the Webpack solution相同的方式来解决这个问题:将express包标记为外部包。它看起来像这样:
esbuild index.js --bundle --platform=node --outfile=server.js --external:expresshttps://stackoverflow.com/questions/65009722
复制相似问题