使用我自己的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.
package.json
的{{1}}是:
duplicate-module-name-npm
对于{
"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
我尝试了提到的here解决方案,即添加了{
"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
具有MWE的回购在https://github.com/zxl634/duplicate-module-name-npm和https://github.com/zxl634/duplicate-module-name上可用。
运行const blacklist = require('metro-config/src/defaults/blacklist');
module.exports = {
resolver: {
blacklistRE: blacklist([
/duplicate-module-name-npm\/.*/,
])
},
};
后出现错误。
任何帮助或建议都非常感激:)
答案 0 :(得分:0)
通过将路径添加到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
。