4

当我npm install从 react-boilerplate 项目运行时,我的几个 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
4

1 回答 1

2

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

文档

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

于 2016-09-14T22:33:51.670 回答