gpt4 book ai didi

node.js - 如何使用 react-boilerplate 修复 `npm install` 错误?

转载 作者:搜寻专家 更新时间:2023-10-31 23:20:26 24 4
gpt4 key购买 nike

当我从 react-boilerplate 项目运行 npm install 时,我的几个第 3 方模块会发出错误,如下所示。所有这些模块在其他 Node 项目中都可以正常工作,只是在 react-boilerplate 中不行。有谁知道如何解决这些问题?

ERROR in ./~/nconf/lib/nconf.js
Module not found: Error: Can't resolve 'fs' in '/Users/me/src/fullboar/probate-web/node_modules/nconf/lib'
@ ./~/nconf/lib/nconf.js 8:9-22

ERROR in ./~/nconf/package.json
Module parse failed: /Users/me/src/fullboar/probate-web/node_modules/nconf/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| {
@ ./~/nconf/lib/nconf.js 21:16-42

ERROR in ./~/nconf/lib/nconf/common.js
Module not found: Error: Can't resolve 'fs' in '/Users/me/src/fullboar/probate-web/node_modules/nconf/lib/nconf'
@ ./~/nconf/lib/nconf/common.js 8:9-22

ERROR in ./~/sequelize/package.json
Module parse failed: /Users/me/src/fullboar/probate-web/node_modules/sequelize/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| {
@ ./~/sequelize/lib/sequelize.js 265:20-46

最佳答案

我在 fs 包上遇到了同样的问题。

ERROR in dll reactBoilerplateDeps
Module not found: Error: Can't resolve 'fs' in '/Users/nico/_dev/crf'
@ dll reactBoilerplateDeps

为了避免这个错误,我忽略了浏览器构建更新 webpack.dll.babel.jsfs 模块。像这样的文件:

  // ...
plugins: [
new webpack.DllPlugin({ name: '[name]', path: join(outputPath, '[name].json') }), // eslint-disable-line no-new
],

// mock fs
node: {
fs: 'empty',
},
};

我不知道这是否是最好的解决方案,但对我来说效果很好。

注意

之前:

  • 我尝试了 rm -r node_modules && npm cache clean && npm install 但错误仍然存​​在

  • 我在internals/config.js 的dllPlugin exclude 数组中插入了fs 依赖项|文件,但错误依旧

文档

node webpack 配置中的关键包括各种 Node 内容的 polyfills 或 mocks

关于node.js - 如何使用 react-boilerplate 修复 `npm install` 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136933/

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