Webpack:未定义要求(查询字符串)?
Web pack: require is note defined (query string)?
我做了一个 webpack 项目,里面包含了一些 web3js 和文件系统模块。当我 运行 本地主机时出现此错误。
在控制台中
Uncaught ReferenceError: require is not defined
at Object.querystring (external "querystring":1)
at __webpack_require__ (bootstrap:19)
at Object.<anonymous> (client:6)
at Object../node_modules/webpack-dev-server/client/index.js?http://localhost (bundle.js:98107)
at __webpack_require__ (bootstrap:19)
at Object.0 (bundle.js:103438)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83
我完全不知道这个错误是什么意思。
文件
module.exports = require("querystring");
webpack.config.js
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
devServer: {
contentBase: './dist'
},
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
}
]
},
target: 'node'
};
已编辑:我无法添加 target:'browser'
因为它会使文件系统模块 'fs' 不可读
是我的错。我尝试在浏览器而不是服务器上使用 javascript 文件 运行。 require
并且所有全局变量只有在您将它们包含在服务器上时才有效。
我做了一个 webpack 项目,里面包含了一些 web3js 和文件系统模块。当我 运行 本地主机时出现此错误。
在控制台中
Uncaught ReferenceError: require is not defined
at Object.querystring (external "querystring":1)
at __webpack_require__ (bootstrap:19)
at Object.<anonymous> (client:6)
at Object../node_modules/webpack-dev-server/client/index.js?http://localhost (bundle.js:98107)
at __webpack_require__ (bootstrap:19)
at Object.0 (bundle.js:103438)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83
我完全不知道这个错误是什么意思。
文件
module.exports = require("querystring");
webpack.config.js
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
devServer: {
contentBase: './dist'
},
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
}
]
},
target: 'node'
};
已编辑:我无法添加 target:'browser'
因为它会使文件系统模块 'fs' 不可读
是我的错。我尝试在浏览器而不是服务器上使用 javascript 文件 运行。 require
并且所有全局变量只有在您将它们包含在服务器上时才有效。