React-Native打包程序失败:模块名重复

16

这似乎是在开发过程中随机发生的。当尝试运行 npm startreact-native run-ios 时,我会遇到以下错误:

Failed to build DependencyGraph: @providesModule naming collision:
  Duplicate module name: react-native-vector-icons
  Paths: /Users/chandlervdw/Repos/Relay/mobile/node_modules/react-native/local-cli/rnpm/core/test/fixtures/files/package.json collides with /Users/chandlervdw/Repos/Relay/mobile/node_modules/react-native/Libraries/Animated/release/package.json

This error is caused by a @providesModule declaration with the same name accross two different files.
Error: @providesModule naming collision:
  Duplicate module name: react-native-vector-icons
  Paths: /Users/chandlervdw/Repos/Relay/mobile/node_modules/react-native/local-cli/rnpm/core/test/fixtures/files/package.json collides with /Users/chandlervdw/Repos/Relay/mobile/node_modules/react-native/Libraries/Animated/release/package.json

This error is caused by a @providesModule declaration with the same name accross two different files.
    at HasteMap._updateHasteMap (/Users/chandlervdw/Repos/Relay/mobile/node_modules/node-haste/lib/DependencyGraph/HasteMap.js:162:15)
    at /Users/chandlervdw/Repos/Relay/mobile/node_modules/node-haste/lib/DependencyGraph/HasteMap.js:140:25

奇怪的是,/Users/chandlervdw/Repos/Relay/mobile/node_modules/react-native/local-cli/rnpm/core/test/fixtures/files/package.json 实际上将 react-native-vector-icons 列为该模块的名称???

如果我删除那个文件,错误就不会再发生了,但打包程序会在93%处卡住,并抱怨找不到一个完全无关的库。

我清除了我的存储库,甚至重新安装了所有东西,包括 npmrnpm,甚至升级了 node。我正在运行与我的团队成员相同版本的一切,他们能够无问题地运行打包程序。


1
我知道这听起来很傻,但你尝试使用sudo权限运行了吗?当我尝试构建React Native for Android时,遇到了类似的错误,使用sudo运行解决了冲突。 - Halfpint
1
@Alex 你一定在开玩笑吧。这个方法居然管用了!但是为什么啊?!?!我因为这个浪费了一整天的时间…… - chandlervdw
1
@chandlervdw 相信我,伙计,这周我也遇到了同样的问题,很抱歉你不得不浪费这么多时间在这个错误上...我也像你一样撞墙,尝试了所有其他途径!有时候你不是很喜欢npm包管理器吗?很高兴你解决了这个问题 :) - Halfpint
2
我的猜测是,在构建该软件包时,它需要访问一些受限资源,这需要sudo授予的提升权限...我只希望错误代码不要那么模糊! - Halfpint
谢谢 - 在周末花了几个小时遇到了随机的红屏,真是难以置信!非常好的提示,已经收藏了! - VineFreeman
4个回答

8

将此作为答案发布,以防将来有其他人遇到此问题。

在节点包管理器运行初始构建阶段时,使用sudo权限运行 npm start 将授予正确的特权。这只会发生在运行命令的 shell/user 具有受限特权的情况下。强制升级权限为 sudo 可以使包管理器完全控制完成构建。


4

我一直在遇到像下面这样的错误:

Failed to build DependencyGraph: @providesModule naming collision:
Failed to build DependencyGraph: @providesModule naming collision:
Duplicate module name: accepts
Duplicate module name: accepts

我通过删除npm的缓存.npm并使用--reset-cache重新运行packager解决了这个问题。

rm -rf ~/.npm

这应该是被接受的答案,因为我发现其他答案有点“作弊”,因为我通常从不使用sudo - Greg
@Greg 别忘了,在 Windows 上不存在 "Sudo" 命令,也不应该使用它来解决权限错误。 - Hobbyist

4

sudochown 对我没有起作用。我从同一个库得到了相同的错误,非常奇怪:

Failed to build DependencyGraph: @providesModule naming collision:
 Duplicate module name: react-native-vector-icons
  Paths: /Users/collumj/research/k9fresh/ios/build/Build/Products/Debug-iphonesimulator/kisharNine.app/package.json collides with /Users/collumj/research/k9fresh/node_modules/react-native/local-cli/core/__fixtures__/files/package.json

当我遇到这种情况时,不需要使用sudo

警告:此操作具有破坏性,请先进行检查。

rm -rf android ios
git reset --hard
npm start

每次都可以用此方法解决。RN 0.39.2

编辑:后来,我认为我是通过取消链接react-native-vector-icons库来解决这个问题的;我认为我得到的说明让我在链接上重复了一遍,或者某种方式已经过时。


3

清理nvm缓存并重新安装所有node_modules后,我意识到这个问题是由于react-native-router-flux引起的。

我通过降级解决了它,从react-native-router-flux@3.38.1降级到react-native-router-flux@3.38.0

更多细节请参见: https://github.com/aksonov/react-native-router-flux/issues/1816


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接