错误:jest-haste-map:使用本地依赖时@providesModule 命名冲突 [英] Error: jest-haste-map: @providesModule naming collision when using a local dependency

查看:25
本文介绍了错误:jest-haste-map:使用本地依赖时@providesModule 命名冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 package.json 中使用了一个本地模块,该模块也有 react-native 作为依赖项.

I'm using a local module in package.json that also has react-native as a dependency.

在我的应用程序 package.json 中:

In my APP package.json:

"react": "16.4.1",
"react-native": "0.56.0",
"react-native-services": "file:///Users/R01/Projects/react-native-services"

在我的 react-native-services package.json 中:

"react": "16.4.1",
"react-native": "0.56.0"

所以当运行 react-native run-android 时,Metro Bundler 抛出:

So when running react-native run-android the Metro Bundler throws:

Looking for JS files in
   /Users/R01/Projects/RNApp
   /Users/R01/Projects/react-native-services 


Metro Bundler ready.

Loading dependency graph...(node:72824) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: Sample
  Paths: /Users/R01/Projects/react-native-services/node_modules/react-native/Libraries/Sample/package.json collides with /Users/R01/Projects/RNApp/node_modules/react-native/Libraries/Sample/package.json

 This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
(node:72824) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:72824) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error: bundling failed: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: Sample
  Paths: /Users/R01/Projects/react-native-services/node_modules/react-native/Libraries/Sample/package.json collides with /Users/R01/Projects/RNApp/node_modules/react-native/Libraries/Sample/package.json

This error is caused by a @providesModule declaration with the same name across two different files.
    at setModule (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:446:17)
    at workerReply (/Users/R01/Projects/RNApp/node_modules/jest-haste-map/build/index.js:496:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)

我已经试过了:

  • 使用 npmyarn(升级)安装但 react-native run-android 总是抛出相同的错误.
  • watchman watch-del-all rm -rf node_modules &&npm install rm -fr $TMPDIR/react-* npm cache clean npm start -- --reset-cache
  • With both npm and yarn (upgraded) installations but react-native run-android throws always the same error.
  • watchman watch-del-all rm -rf node_modules && npm install rm -fr $TMPDIR/react-* npm cache clean npm start -- --reset-cache

推荐答案

面临同样的问题解决了!!

Faced same issue Resolved it !!

项目中所有的 npm 包都有 node 模块.确保包内的 node_modules 目录不应包含已存在的节点模块.

All the npm packages in project have node modules. Make sure that node_modules directory inside packages should not include already present node module.

就我而言,react-native 出现在我项目的 node_modules 以及另一个分叉库的 node_modules 中.

In my case react-native was present in node_modules of my project as well as node_modules of another forked library.

由于库被分叉,我可以从中删除 node_modules 目录,问题得到解决.

As the library was forked, I could remove node_modules directory from it and the issue got resolved.

这篇关于错误:jest-haste-map:使用本地依赖时@providesModule 命名冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆