React Native 0.16 新建工程 Babel 报错



  • 使用命令初始化项目:

    react-native init test
    

    但遇到如下报错:

    This will walk you through creating a new React Native project in /Users/Bell/Downloads/rn/test
    Installing react-native package from npm...
    /Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/file/logger.js:41
        throw new Constructor(this._buildMessage(msg));
        ^
    
    ReferenceError: [BABEL] /Users/Bell/Downloads/rn/test/node_modules/react-native/local-cli/bundle/bundle.js: Unknown option: base.whitelist
        at Logger.error (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/file/logger.js:41:11)
        at OptionManager.mergeOptions (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/file/options/option-manager.js:262:18)
        at OptionManager.init (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)
        at File.initOptions (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/file/index.js:190:75)
        at new File (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/file/index.js:121:22)
        at Pipeline.transform (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
        at Object.transformFileSync (/Users/Bell/Downloads/rn/test/node_modules/babel-core/lib/api/node.js:116:10)
        at compile (/Users/Bell/Downloads/rn/test/node_modules/babel-register/lib/node.js:102:20)
        at loader (/Users/Bell/Downloads/rn/test/node_modules/babel-register/lib/node.js:130:14)
        at Object.require.extensions.(anonymous function) [as .js] (/Users/Bell/Downloads/rn/test/node_modules/babel-register/lib/node.js:140:7)
    

    我了解到 0.16 是使用了 babel 6,但我之前没有配置过 babel,不知道这个问题如何定位、解决。

    PS,我下载了论坛提供的 RN 0.16 包,运行react-native run-android也是报同样的错误......



  • Unknown option: base.whitelist看起来是某个BABEL新的option认不出,是不是还是用的老版本?建议删掉node_modules目录夹后,再npm install试试。

    另外npm可以使用淘宝镜像,速度杠杠的。



  • @ericguo 感谢回复,应该是 Babel 设置的问题,但我是新建项目,之前也没有 Babel 的相关设置,所以个报错很奇怪。