使用react-native时,我在启动命令时遇到错误。文件 PROJECTNAME /node_modules/@babel/core/lib/transformation/file/file.js 在第63行给出错误
constructor(options, {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Module._extensions..js (module.js:417:10)
at Object.require.extensions.(anonymous function) [as .js] (/home/cread/WHOOP-ReactNative/whoopApp/node_modules/babel-register/lib/node.js:152:7)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/cread/WHOOP-ReactNative/whoopApp/node_modules/@babel/core/lib/index.js:123:36)
at Module._compile (module.js:410:26)
这是我的package.json文件
{
"name": *name*,
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.3.0-alpha.2",
"react-native": "0.54.2",
"react-native-elements": "^0.19.1",
"react-native-keyboard-aware-scroll-view": "^0.5.0",
"react-native-modal-dropdown": "^0.6.2",
"react-native-sound": "0.10.9",
"react-native-vector-icons": "^4.5.0",
"react-navigation": "^1.5.8"
},
"devDependencies": {
"babel-jest": "23.0.0-alpha.0",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.2",
"react-test-renderer": "16.3.0-alpha.2"
},
"jest": {
"preset": "react-native"
}
}
我尝试删除我的node_modules文件,清除npm缓存,然后重新安装但无效。问题似乎出现在cli.js文件中。
答案 0 :(得分:5)
我使用的是react-native和nodejs的最新版本。不幸的是,我需要回到版本8.11.2。在我的情况下,它已得到解决。 我删除了node_modules目录。
$ rm -rf node_modules
$ nvm install 8.11.2
$ nvm use 8.11.2
$ npm install react-native@0.54.1