【问题标题】:How do I fix `npm install` errors with react-boilerplate?如何使用 react-boilerplate 修复“npm install”错误?
【发布时间】:2016-08-25 04:56:23
【问题描述】:

当我从 react-boilerplate 项目运行 npm install 时,我的几个 3rd 方模块会发出如下所示的错误。所有这些模块在其他节点项目中都可以正常工作,只是在 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

【问题讨论】:

  • 尝试将您的节点更新到最新版本
  • 我正在运行v4.5.0
  • 我也有同样的问题,没有一个解决方案对我不起作用!

标签: node.js reactjs react-boilerplate


【解决方案1】:

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

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

为避免此错误,我忽略了用于浏览器构建的 fs 模块,像这样更新 webpack.dll.babel.js 文件:

  // ...
  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文件中的dllPluginexclude数组中插入了fs依赖,但错误依然存在

文档

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2019-05-02
    • 2020-06-26
    • 2014-10-07
    • 1970-01-01
    相关资源
    最近更新 更多