【发布时间】:2019-09-19 10:46:42
【问题描述】:
我做了一个 webpack 项目,并在其中包含了一些 web3js 和文件系统模块。当我运行 localhost 时出现此错误。
在控制台中
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 webpack fs solidity web3