react-native - 意外使用保留字 'import React-native

标签 react-native babeljs

enter image description here 我的 bable.src 文件代码在这里

 {
  "presets": ["es2015"]
}

Package.json 文件代码在这里
{
        "name": "Zoylo",
        "version": "0.0.1",
        "private": true,
        "scripts": {
            "start": "node node_modules/react-native/local-cli/cli.js start",
            "postinstall": "rm ./node_modules/react-native/local-cli/core/__fixtures__/files/package.json",
            "test": "jest"
        },
        "dependencies": {
            "@ptomasroos/react-native-multi-slider": "0.0.11",
            "babel-core": "^6.26.0",
            "babel-loader": "^7.1.2",
            "jwt-node-decoder": "0.0.4",
            "npm": "^5.3.0",
            "prop-types": "^15.6.1",
            "react": "^16.2.0",
            "react-dom": "^16.3.2",
            "react-native": "^0.52.0",
        },
        "devDependencies": {
            "babel-eslint": "^8.0.3",
            "babel-jest": "20.0.3",
            "babel-plugin-transform-export-extensions": "^6.22.0",
            "babel-preset-env": "^1.6.1",
            "babel-preset-es2015": "^6.24.1",
            "babel-preset-react": "^6.24.1",
            "babel-preset-react-native": "^4.0.0",
            "babel-preset-stage-2": "^6.24.1",
            "jest": "20.0.4",
            "react-test-renderer": "16.0.0-alpha.12"
        },

    }

我认为这是一个 bable 问题。就在 1 天前它工作正常,在 npm install 之后我正面临这个问题。

最佳答案

我得到了答案。我在 .babelrc 文件中遇到了一些问题,现在这是我的新 .babelrc 文件

{ "env": { "test": { "presets": [ "env", "react", "es2015", "stage-2" ], "plugins": [ "transform-export-extensions" ], "only": [ "./**/*.js", "node_modules/jest-runtime" ] } }, "presets": [ "react-native" ] }

并且还需要运行此命令。
watchman watch-del-all && rm -rf node_modules/ && npm cache clean --force && npm install && npm start -- --reset-cache 

关于react-native - 意外使用保留字 'import React-native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50617186/

相关文章:

android - 如何设置android推送通知的颜色和图标?

phantomjs - PhantomJS 对 ES6 的原生支持

node.js - 使 babel 排除测试文件

javascript - Visual Studio 中的 EsLint - 无法在 javascript 文件上使用静态属性

node.js - 警告 : Each child in a list should have a unique "key" prop. %s%s

ios - React Native,面向展览屏幕

html - React Native - 输入顶部的标签

react-native - 无法在 touchablehighlight onpress 中设置状态

javascript - webpack 4 react 意外 token ...(扩展运算符)

reactjs - 使对象传播以使用 webpack.config 和 babelrc 文件