如何使native native packager忽略某些目录

时间:2017-01-23 18:31:30

标签: react-native

问题:

尝试从命令行运行@providesModule naming collision时,我的项目有react-native run-ios。它与自动生成的目录dist/冲突,后者由另一个npm包esdoc创建。我希望能够保留这个自动生成的目录,并让反应原生包装器忽略dist/目录。

错误讯息:

[01/23/2017, 13:17:07] <START> Building Haste Map
    Failed to build DependencyGraph: @providesModule naming collision:
      Duplicate module name: ann
      Paths: /Users/thurt/projects/example/package.json collides with /Users/thurt/projects/example/dist/esdoc/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
Error: @providesModule naming collision:
  Duplicate module name: ann
  Paths: /Users/thurt/projects/example/package.json collides with /Users/thurt/projects/example/dist/esdoc/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
    at HasteMap._updateHasteMap (/Users/thurt/projects/example/node_modules/react-native/packager/react-packager/src/node-haste/DependencyGraph/HasteMap.js:158:13)
    at p.getName.then.name (/Users/thurt/projects/example/node_modules/react-native/packager/react-packager/src/node-haste/DependencyGraph/HasteMap.js:133:31)

1 个答案:

答案 0 :(得分:22)

你几乎在https://github.com/facebook/react-native/issues/12131

您可以在项目根目录中创建一个名为rn-cli.config.js的文件,其中包含(特定于版本的)内容,如下所示:

对于原生反应&gt; = 0.57

const blacklist = require('metro-config/src/defaults/blacklist');

// blacklist is a function that takes an array of regexes and combines
// them with the default blacklist to return a single regex.

module.exports = {
  resolver: {
    blacklistRE: blacklist([/dist\/.*/])
  }
};

对于反应原生&gt; = 0.52,&lt; 0.57

const blacklist = require('metro').createBlacklist;

module.exports = {
  getBlacklistRE: function() {
    return blacklist([/dist\/.*/]);
  }
};

对于React Native&gt; = 0.46,&lt; 0.52 即可。

const blacklist = require('metro-bundler').createBlacklist;

module.exports = {
  getBlacklistRE: function() {
    return blacklist([/dist\/.*/]);
  }
};

对于React Native&lt; 0.46 即可。

const blacklist = require('react-native/packager/blacklist');

module.exports = {
  getBlacklistRE: function() {
    return blacklist([/dist\/.*/]);
  }
};

所有版本:

通过传递--config选项让您的CLI命令使用此配置:

react-native run-ios --config=rn-cli.config.js

(NB可能是您需要传递--config参数的错误,此位置可能应该自动加载,但node_modules/react-native/rn-cli.config.js优先)

请注意,您的dist文件夹可能已被包装程序缓存,在第一次运行时,您可能需要重置缓存:

react-native start --config=rn-cli.config.js --resetCache