2017-01-23 54 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