我刚刚从RN 0.55.4升级到0.59.3 .....现在我收到以下错误消息:
错误:无法从..... node_modules \ react-native \ Libraries \ Utilities \ HMRClient.js解析模块Metro / src / lib / bundle-modules / HMRClient:模块Metro / src / lib / bundle-modules / HMRClient在快捷模块映射中不存在
HMRClient.js文件确实包含以下require语句:const MetroHMRClient = require('metro/src/lib/bundle-modules/HMRClient');
.....而且我在任何地方都看不到以“ metro”开头的路径,所以我想我需要以某种方式添加它。还有另一条require语句,如下:const invariant = require('invariant');
.....也没有文件名“ invariant”。
Facebook表示此问题已在0.53.0主版本中修复,但看起来像 https://github.com/facebook/react-native/issues/17742
下面是我的package.json
{
"name": "xs",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"flow": "flow",
"flow start": "flow start",
"flow stop": "flow stop",
"flow status": "flow status",
"flow coverage": "flow coverage"
},
"dependencies": {
"firebase": "^5.11.1",
"flow": "^0.2.3",
"flow-bin": "^0.65.0",
"prop-types": "^15.6.1",
"react": "16.8.3",
"react-native": "0.59.3",
"react-native-elements": "^0.19.0",
"react-native-google-places-autocomplete": "^1.3.9",
"react-native-maps": "git://github.com/react-native-community/react-native-maps.git#master",
"react-native-switch": "^1.4.0",
"react-native-vector-icons": "^4.5.0",
"react-navigation": "^2.5.5",
"react-redux": "^5.1.0",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"babel-eslint": "^8.2.6",
"babel-preset-flow": "^6.23.0",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"prettier-eslint": "^8.8.2",
"@babel/core": "^7.4.3",
"@babel/runtime": "^7.4.3",
"babel-jest": "^24.7.1",
"jest": "^24.7.1",
"metro-react-native-babel-preset": "^0.53.1",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
}
}
请帮助!
p.s。以下建议不起作用
要解决此问题,请尝试以下操作:
1.清除值班员手表:watchman watch-del-all
。
2.删除node_modules
文件夹:rm -rf node_modules && npm install
。
3.重置Metro Bundler缓存:rm -rf /tmp/metro-bundler-cache-*
或npm start -- --reset-cache
。
4.删除急速缓存:rm -rf /tmp/haste-map-react-native-packager-*
。
答案 0 :(得分:2)
运行npm install
时请注意是否需要特定版本的东西。
首先检查babel的配置文件,然后如果不起作用,请尝试在package.json
中进行更改。
尝试如下配置文件和部署。 这是一个对我有用的配置,可以将其从0.54更新到0.59.5:
package.json:
" dependencies": {
"react": "16.8.3",
"react-native": "0.59.5",
// ...
},
"devDependencies": {
"@babel/core": "^7.0.0-0",
"babel-core": "^7.0.0-bridge.0",
"metro-react-native-babel-preset": "0.53.0",
"react-test-renderer": "16.6.3",
// ...
}
babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
.babelrc:
{
"presets": ["module:metro-react-native-babel-preset"]
}
我可以在RN发行说明中找到有关babel和Metro更改的唯一有用信息,位于[0.57]:
https://github.com/react-native-community/releases/blob/master/CHANGELOG.md
更新说明:
尝试将配置文件作为新的工作项目(使用0.59.9创建)中的配置文件尝试将其从0.54更新到0.59无效
babel.config.js:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
metro.config.js:
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
};
,没有.babelrc
文件。
package.json:
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/runtime": "^7.4.5",
"metro-react-native-babel-preset": "^0.54.1",
},