我有一些错误的webpack 5,表示,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还有15次警告。如果你想听警告,告诉我。
有什么问题吗?
下面是webpack.config.js
const webpack = require("webpack");
module.exports = {
target: "async-node",
mode: "production",
entry: "./app.js",
output: {
path: "/dist",
filename: "main.js",
},
plugins: [
new webpack.DefinePlugin({
"process.env.PA_URL": JSON.stringify(process.env.PA_URL),
"process.env.PA5_EMAIL": JSON.stringify(process.env.PA5_EMAIL),
"process.env.PA5_PASSWORD": JSON.stringify(process.env.PA5_PASSWORD),
}),
],
};webpack版本是错的吗?
发布于 2022-02-11 16:45:10
您正在捆绑您的输入文件,但也绑定了您的./app.js所需的任何./app.js,这反过来又试图要求一堆第三方的东西,这些东西是不可用的,因此出现了丢失模块上的错误。
通过扩展webpack配置:node_modules (参见: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这应该把他们排除在外,你应该做得很好。
https://stackoverflow.com/questions/71013802
复制相似问题