Lun*_*712 5 node.js express webpack github-actions webpack-5
我在 webpack 5、express、github 操作中遇到一些错误。我使用 github 操作是因为想使用 github 秘密。另外,我使用 webpack 因为使用了代码中的秘密。
无论如何,我在下面遇到了错误,
ERROR in ./node_modules/terser-webpack-plugin/dist/utils.js 479:6-26
Module not found: Error: Can't resolve 'uglify-js' in '/Users/luna/workspace/express_api/node_modules/terser-webpack-plugin/dist'
@ ./node_modules/terser-webpack-plugin/dist/index.js 27:4-22
@ ./webpack.config.js 2:21-53
@ ./app.js 13:15-45
ERROR in ./node_modules/terser-webpack-plugin/dist/utils.js 557:14-34
Module not found: Error: Can't resolve '@swc/core' in '/Users/luna/workspace/express_api/node_modules/terser-webpack-plugin/dist'
@ ./node_modules/terser-webpack-plugin/dist/index.js 27:4-22
@ ./webpack.config.js 2:21-53
@ ./app.js 13:15-45
ERROR in ./node_modules/terser-webpack-plugin/dist/utils.js 635:18-36
Module not found: Error: Can't resolve 'esbuild' in '/Users/luna/workspace/express_api/node_modules/terser-webpack-plugin/dist'
@ ./node_modules/terser-webpack-plugin/dist/index.js 27:4-22
@ ./webpack.config.js 2:21-53
@ ./app.js 13:15-45
Run Code Online (Sandbox Code Playgroud)
此外,还收到了 15 条警告。如果您想要警告,请告诉我。
问题是什么?
下面是 webpack.config.js
ERROR in ./node_modules/terser-webpack-plugin/dist/utils.js 479:6-26
Module not found: Error: Can't resolve 'uglify-js' in '/Users/luna/workspace/express_api/node_modules/terser-webpack-plugin/dist'
@ ./node_modules/terser-webpack-plugin/dist/index.js 27:4-22
@ ./webpack.config.js 2:21-53
@ ./app.js 13:15-45
ERROR in ./node_modules/terser-webpack-plugin/dist/utils.js 557:14-34
Module not found: Error: Can't resolve '@swc/core' in '/Users/luna/workspace/express_api/node_modules/terser-webpack-plugin/dist'
@ ./node_modules/terser-webpack-plugin/dist/index.js 27:4-22
@ ./webpack.config.js 2:21-53
@ ./app.js 13:15-45
ERROR in ./node_modules/terser-webpack-plugin/dist/utils.js 635:18-36
Module not found: Error: Can't resolve 'esbuild' in '/Users/luna/workspace/express_api/node_modules/terser-webpack-plugin/dist'
@ ./node_modules/terser-webpack-plugin/dist/index.js 27:4-22
@ ./webpack.config.js 2:21-53
@ ./app.js 13:15-45
Run Code Online (Sandbox Code Playgroud)
webpack版本不对?
小智 7
您正在捆绑您的入口文件,但也捆绑了node_modules您的任何./app.js需求,这反过来又试图需要一堆第三方的东西,而这些东西是不可用的 - 因此会出现缺少模块的错误。
node_modules通过扩展您的 webpack 配置来
排除这些:(yarn add -D webpack-node-externals
请参阅: https: //www.npmjs.com/package/webpack-node-externals)
const webpack = require("webpack");
const nodeExternals = require("webpack-node-externals");
module.exports = {
target: "async-node",
mode: "production",
entry: "./app.js",
externalsPresets: { node: true }, // <-- here
externals: [nodeExternals()], // <-- and here
...etc
Run Code Online (Sandbox Code Playgroud)
这应该排除他们,你应该可以走了。
| 归档时间: |
|
| 查看次数: |
4633 次 |
| 最近记录: |