【发布时间】:2017-05-16 10:20:26
【问题描述】:
我一直遇到这个错误。它最近发生了几次,现在我无法摆脱它。我在我的 React Native 项目中使用 MobX,所以我的 .babelrc 中需要一些东西,所以我有装饰器支持:
{
"presets": ["react-native"],
"plugins": ["transform-decorators-legacy"]
}
我尝试了一些不同的变化,但都给了我下面的错误。如果我删除它,由于不支持装饰器,我会收到错误消息。
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' (1:0)
at Parser.pp$5.raise (/path-to/node_modules/babylon/lib/index.js:4246:13)
at Parser.pp$1.parseStatement (/path-to/node_modules/babylon/lib/index.js:1749:16)
at Parser.pp$1.parseBlockBody (/path-to/node_modules/babylon/lib/index.js:2133:21)
at Parser.pp$1.parseTopLevel (/path-to/node_modules/babylon/lib/index.js:1645:8)
at Parser.parse (/path-to/node_modules/babylon/lib/index.js:1537:17)
at Object.parse$1 [as parse] (/path-to/node_modules/babylon/lib/index.js:6466:37)
at extractDependencies (/path-to/node_modules/react-native/packager/react-packager/src/JSTransformer/worker/extract-dependencies.js:29:23)
at transform (/path-to/node_modules/react-native/packager/react-packager/src/JSTransformer/worker/index.js:53:9)
at module.exports (/path-to/node_modules/react-native/packager/transformer.js:130:3)
at transformCode (/path-to/node_modules/react-native/packager/react-packager/src/JSTransformer/worker/index.js:27:3)
transformed 35/139 (25%)/path-to/node_modules/babylon/lib/index.js:4249
throw err;
我已经尝试删除我的 node_modules 并重新安装了几次。我正在使用纱线。在再次运行yarn install 之前也删除了锁定文件。
我关注this guide 安装了 Babel 插件。
我的package.json 看起来像:
"dependencies": {
"apsl-react-native-button": "^3.0.0",
"mobx": "^2.5.0",
"mobx-react": "^3.5.5",
"react": "15.3.2",
"react-native": "0.37.0",
"react-native-autogrow-textinput": "^2.0.3",
"react-native-awesome-button": "^1.6.0",
"react-native-couchbase-lite": "git://github.com/adamski/react-native-couchbase-lite.git#gradle-experimental",
"react-native-keep-awake": "git://github.com/adamski/react-native-keep-awake.git#experimental-gradle",
"react-native-keyboard-aware-view": "^0.0.11",
"react-native-keyboard-dodging-view": "git://github.com/adamski/react-native-keyboard-dodging-view#upper-text-inputs",
"react-native-modalbox": "^1.3.4",
"react-native-navigation": "git://github.com/adamski/react-native-navigation.git#gradle-experimental-update",
"react-native-searchbar": "^0.4.2",
"react-native-simple-store": "^1.0.1",
"react-native-swipe-list-view": "^0.3.1"
},
"devDependencies": {
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-react-native": "^1.9.1"
}
我尝试更新到 RN 0.38,但仍然遇到同样的错误。
运行ag babylon 产生
yarn.lock
200: babylon "^6.11.0"
885: babylon "^6.11.0"
896: babylon "^6.11.0"
911:babylon@^6.11.0, babylon@^6.13.0, babylon@^6.13.1:
913: resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.14.1.tgz#956275fab72753ad9b3435d7afe58f8bf0a29815"
3478: babylon "^6.13.0"
3555: babylon "^6.13.1"
这表明不同版本的巴比伦之间存在冲突?
谁能告诉我这个错误信息的真正含义?是我的代码中的某些东西,还是我的模块之间的 babel 版本不匹配?
【问题讨论】:
-
哪个模块没有被导入?
-
@Codesingh 我不知道..
-
从你项目的根目录运行 npm uninstall
-
让我看看你的 package.json
-
@Codesingh 添加了完整的 package.json 详细信息
标签: react-native babeljs mobx