代码之家  ›  专栏  ›  技术社区  ›  Cread Dotson

响应本机启动意外令牌

  •  4
  • Cread Dotson  · 技术社区  · 6 年前

    使用react native时,start命令出错。文件 项目名称 /节点模块/@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"
      }
    }
    

    我尝试删除我的节点模块文件,清除NPM缓存,然后重新安装,但没有用。问题似乎出在cli.js文件中。

    1 回复  |  直到 6 年前
        1
  •  5
  •   Marcelo Oliveira    6 年前

    我使用的是最新版本的react native和nodejs。不幸的是,我需要回到8.11.2版。在我的情况下,解决了这个问题。 我删除了node_modules dir。

    $ rm -rf node_modules
    $ nvm install 8.11.2
    $ nvm use 8.11.2
    $ npm install react-native@0.54.1