gpt4 book ai didi

node.js - Uncaught Error : Cannot find module "fs" when using webpack

转载 作者:太空宇宙 更新时间:2023-11-03 21:53:25 24 4
gpt4 key购买 nike

我正在使用 webpack + React + Nodejs,这是我的 webpack 配置文件:

当我在浏览器上打开网站时,它返回未捕获错误:无法在浏览器上找到模块“fs”。

var webpack = require('webpack');

var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
entry: [
'script-loader!./public/js/vendor/jquery.js',
'script-loader!./public/js/vendor/foundation.min.js',
'script-loader!./public/js/app.js',
'./view/app.jsx',
'./view/styles/main.scss'
],
externals: {
jquery: 'jQuery'
},
plugins: [
new ExtractTextPlugin({
filename: './public/styles/bundle.css',
allChunks: true,
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
],
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve: {
alias: {
view: path.join(__dirname, 'view'),
componentDir: path.join(__dirname, 'view/components/'),
configureStore: path.resolve(__dirname, 'view/store/configureStore/'),
actions: path.resolve(__dirname, 'view/actions/index/')
},
extensions: ['.js', '.jsx']
},
module: {
rules: [
...
]
}

};

问题出在哪里?

最佳答案

我认为你必须添加

node: {
fs: 'empty',
},

到你的 webpack 配置。 (https://webpack.js.org/configuration/node/#node)

关于node.js - Uncaught Error : Cannot find module "fs" when using webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com