简体   繁体   English

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

[英]How do I fix `npm install` errors with react-boilerplate?

When I run npm install from a react-boilerplate project several of my 3rd party modules give off errors like you see below. 当我从react-boilerplate项目运行npm install ,我的第三方模块会发出如下所示的错误。 All these modules work fine in other node projects, just not in react-boilerplate. 所有这些模块在其他节点项目中都能正常工作,而不是在反应模板中。 Does anyone know how to fix these? 有谁知道如何解决这些问题?

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

I've the same issue on fs package. 我在fs包上遇到了同样的问题。

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

To avoid this error I ignore the fs module for browser builds updating the webpack.dll.babel.js file like this: 为了避免这个错误,我忽略用于浏览器构建的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',
  },
};

I don't know if is the best solution, but for me works fine. 我不知道是否是最好的解决方案,但对我来说工作正常。

NOTE 注意

Before: 之前:

  • I tried to rm -r node_modules && npm cache clean && npm install but the error remained 我试着rm -r node_modules && npm cache clean && npm install但错误仍然存​​在

  • I inserted the fs dependency in the dllPlugin exclude array in internals/config.js file, but the error remained 我在internals / config.js文件中的dllPlugin exclude数组中插入了fs依赖项,但错误仍然存​​在

Documentation 文档

node key in webpack config include polyfills or mocks for various node stuff webpack配置中的node键包括用于各种节点内容的polyfill或mocks

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM