关键依赖关系:require函数以无法静态提取依赖的方式使用-NodeJS,Express和Webpack



我正在使用Node.js, Express &Webpack。一切都很顺利,直到Webpack升级到Webpack 5,出现了很多bug。我已经解决了所有的错误,但有一个警告,我不能解决。我看过这篇文章,但它与Angular有关,所以我不认为它对我有多大帮助:关键依赖:require函数的使用方式是无法静态提取依赖

WARNING in ./node_modules/terser-webpack-plugin/dist/minify.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

这是我的webpack.config.js;解析字段和node-polyfill-webpack-plugin用于解决Webpack 5的错误。

const path = require("path")
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
const webpack = require('webpack')
const HtmlWebPackPlugin = require("html-webpack-plugin")
module.exports = {
resolve:{
fallback: {
"fs": false,
"path": false,
"worker_threads":false,
"child_process":false,
"http": false,
"https": false,
"stream": false,
"crypto": false,  
}
},
entry: {
main: './src/js/main.js',
index:'./src/js/'
},
output: {
path: path.join(__dirname, 'dist'),
//publicPath: '/',
filename: '[name].js'
},
mode:"development",
target: 'web',
devtool: 'source-map',
module: {
rules: [
{
test: /.(png|jp(e*)g|svg)$/,  
use: [{
loader: 'url-loader',
options: { 
limit: 8000, // Convert images < 8kb to base64 strings
name: 'images/[hash]-[name].[ext]'
} 
}]
},
{
test: /.js$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /.bpmn$/,
use: 'raw-loader'
},
{
// Loads the javacript into html template provided.
// Entry point is set below in HtmlWebPackPlugin in Plugins 
test: /.html$/,
use: [
{
loader: "html-loader",
//options: { minimize: true }
}
]
},
{
test: /.css$/,
use: [ 'style-loader', 'css-loader' ]
}
]
},
plugins: [
new HtmlWebPackPlugin({
template: '!!raw-loader!./src/views/pages/index.ejs',
filename: "./index.ejs",
excludeChunks: [ 'server', 'main' ]
}),
new HtmlWebPackPlugin({
template: '!!raw-loader!./src/views/pages/bmv.ejs',
filename: "./bmv.ejs",
excludeChunks: [ 'server', 'index' ]
}),
new webpack.NoEmitOnErrorsPlugin(),
new NodePolyfillPlugin()
]
}

配置webpack:

const path = require('path');
module.exports = {
//...
resolve: {
alias: {
'terser-webpack-plugin': path.resolve(__dirname, 'node_modules/terser-webpack-plugin/dist/minify.js'),
},
},
};

相关内容

  • 没有找到相关文章