2017-01-23 56 views
4

问题:试图运行命令行react-native run-ios如何使反应天然打包忽略某些目录

我的项目有一个@providesModule naming collision。它与由另一个npm包esdoc创建的自动生成目录dist/相冲突。我希望能够保留这个自动生成的目录,只是让原本的封装程序忽略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) 

回答

7

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

几乎没有,您可以在项目中创建的根文件名为rn-cli.config.js与内容:

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

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

更新React Native> = 0.46react-native/packager已转移到metro-bundler包。顶(要求)线现在应该是:

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

[结束更新]

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

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

+1

感谢来抢!对于我的情况,我所需要做的就是包含'--reset-cache'标志。现在看来我的'rn-cli.config.js'文件被自动使用了,所以我不需要'--config = rn-cli.config.js'。 成功通过打包程序后,我仍然在应用程序第一次尝试加载时出现“模块未找到”错误。 我将项目文件夹名称添加到黑名单正则表达式的开头,该黑名单似乎解决了该问题。我想我需要确保包装工程师不会忽略像/node_modules//dist/ – thurt

+0

这样的文件夹,您使用哪个版本? –

+0

@GuySegal rn 0.40.0 – thurt