如何使用世博会解决"Duplicate module name: react-native"



我在使用自己的NPM软件包时不断遇到下面的错误,这也取决于 react-native

jest-haste-map: @providesModule naming collision:
      Duplicate module name: react-native
      Paths: /reproducible-bug-examples/duplicate-module-name-npm/node_modules/react-native/package.json collides with /reproducible-bug-examples/duplicate-module-name/node_modules/react-native/package.json
    This error is caused by a @providesModule declaration with the same name across two different files.

duplicate-module-name-npmpackage.json是:

{
  "name": "duplicate-module-name-npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react": "16.5.0"
  },
}

duplicate-module-name是:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "eject": "expo eject",
    "test": "node ./node_modules/jest/bin/jest.js --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/samples": "2.1.1",
    "expo": "^32.0.0",
    "duplicate-module-name-npm": "file:../duplicate-module-name-npm",
    "react": "16.5.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
    "react-navigation": "^3.0.9"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.0.0",
    "jest-expo": "^32.0.0"
  },
  "private": true
}

我尝试了此处提到的解决方案,即添加rn-cli.config.js,但问题仍然存在。确实,在此处添加了所述的内容后,我会收到以下错误:

 (node:31392) UnhandledPromiseRejectionWarning: Error: jest-haste-map: @providesModule naming collision:
  Duplicate module name: react-native
  Paths: /reproducible-bug-examples/duplicate-module-name-npm/node_modules/react-native/package.json collides with /reproducible-bug-examples/duplicate-module-name/node_modules/react-native/package.json
This error is caused by a @providesModule declaration with the same name across two different files.

还尝试将以下内容添加到rn-cli-config.js

const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
  resolver: {
    blacklistRE: blacklist([
      /duplicate-module-name-npm/.*/,
    ])
  },
};

与MWE的存储库可在https://github.com/zxl634/duplicate-module-name-name-name-name-name-name-name-name-name-name-name-name-name and https://github.com/zxl634/duplicate-module-name。

运行expo start后出现错误。

任何帮助或建议都非常感谢:)

通过将路径添加到 rn-cli.config.js的组合:

const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
  resolver: {
    blacklistRE: blacklist([
  /duplicate-module-name-npm/node_modules/react-native/Libraries/Sample/.*/,
  /duplicate-module-name-npm/node_modules/react-native/react-native-git-upgrade/.*/,
  /duplicate-module-name-npm/node_modules/react-native/react-native-cli/.*/,
    ])
  },
};

并更改package.json文件中引起问题的"名称"字段,例如react-native/package.json

相关内容

  • 没有找到相关文章