gpt4 book ai didi

node.js - 将 expressjs 与 esbuild bundle 在一起会给出缺少 view.js 的警告

转载 作者:行者123 更新时间:2023-12-03 12:18:20 27 4
gpt4 key购买 nike

我正在尝试使用 esbuild bundle “express.js”脚本

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
╵ ~~~~~~~

该功能似乎可以运行,但我想找出可能出了什么问题,但我在网上找不到任何提示?

最佳答案

bundle 过程试图生成包含所有代码的单个文件,但警告告诉您 express 包含一些无法 bundle 到单个文件中的代码。我不熟悉 express,但显然这也是 express 和 Webpack 的问题(有关示例,请参见 this question)。

假设您在运行代码时仍将 node_modules/express 文件夹保留在包旁边,您可以使用 esbuild 以相同的方式解决此问题 the Webpack solution工作原理:通过将 express 包标记为外部包。看起来像这样:

esbuild index.js --bundle --platform=node --outfile=server.js --external:express

关于node.js - 将 expressjs 与 esbuild bundle 在一起会给出缺少 view.js 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65009722/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com