反应本机初始化:ReferenceError:[BABEL]未知选项:未知选项:base.optional [英] react native init: ReferenceError: [BABEL] Unknown option: Unknown option: base.optional

查看:101
本文介绍了反应本机初始化:ReferenceError:[BABEL]未知选项:未知选项:base.optional的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行react-native init testNative

ReferenceError: [BABEL] /Users/m/git/testNative/node_modules/react-native/local-cli/bundle/bundle.js: Unknown option: base.optional
    at Logger.error (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/logger.js:41:11)
    at OptionManager.mergeOptions (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/options/option-manager.js:289:18)
    at OptionManager.init (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/options/option-manager.js:486:10)
    at File.initOptions (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/index.js:211:75)
    at new File (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/file/index.js:129:22)
    at Pipeline.transform (/Users/m/git/testNative/node_modules/babel-core/lib/transformation/pipeline.js:48:16)
    at Object.transformFileSync (/Users/m/git/testNative/node_modules/babel-core/lib/api/node.js:118:10)
    at compile (/Users/m/git/testNative/node_modules/babel-register/lib/node.js:100:20)
    at loader (/Users/m/git/testNative/node_modules/babel-register/lib/node.js:128:14)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/m/git/testNative/node_modules/babel-register/lib/node.js:138:7)

我已经尝试了以下帖子中的建议( https://github. com/facebook/react-native/issues/5 https://github.com/babel/babel-loader/issues/132 https://github.com/babel/babelify/issues/129

I've tried the advice in the following posts (https://github.com/facebook/react-native/issues/5, https://github.com/babel/babel-loader/issues/132, https://github.com/babel/babelify/issues/129, React 0.14 error: Module build failed: ReferenceError: [BABEL] .../node_modules/eslint-loader/index.js!/.../main.jsx: Unknown option: base.stage), but with no avail.

我当前的假设是,由于我的系统上没有任何.babelrc文件,因此该文件回落到"base.optional".至少将.babelrc文件添加到我的项目文件夹中是唯一产生不同结果的事情(降级节点,babel或react-native不会执行任何操作).因此,如果这是解决方案,那么有人知道我的.babelrc文件应包含在本机项目中吗?

My current hypothesis is that because I don't have a .babelrc file anywhere on my system, it's falling back to "base.optional." At least adding a .babelrc file to my project folder is the only thing that yielded a different outcome (downgrading node, babel, or react-native did nothing). So, if this is the solution, does anyone know what my .babelrc file should include for a react-native project?

谢谢

推荐答案

此处是可与RN项目一起使用的.babelrc文件之一. 请注意,RN在项目中没有.babelrc文件的情况下也可以正常工作(它会退回到node_modules/react-native/.babelrc文件.

Here is one of the .babelrc files that you can use with your RN project. Note that RN works fine with no .babelrc file in your project (it falls back to node_modules/react-native/.babelrc file.

{
  "retainLines": true,
  "compact": true,
  "comments": false,
  "plugins": [],
  "presets": ["stage-0", "react", "react-native"],
  "sourceMaps": false,
}

您还需要将以下行添加到您的package.json文件中,并安装dev-dependencies:npm i --save-dev <package-name>

You also need to add these line to your package.json file and install the dev-dependencies : npm i --save-dev <package-name>

"devDependencies": {
  "babel-preset-react": "^6.3.13",
  "babel-preset-react-native": "^1.4.0",
  "babel-preset-stage-0": "^6.3.13"
}

这篇关于反应本机初始化:ReferenceError:[BABEL]未知选项:未知选项:base.optional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆