简体   繁体   English

Babel为什么不从事我的React Native项目?

[英]Why isn't Babel working on my React Native project?

I used react-native init and have reached a good point with my app, but now it's giving me serious issues with babel out of nowhere. 我使用了react-native init,并在我的应用程序中达到了一个不错的点,但是现在它给我带来了严重的babel问题。

I got Unexpected use of reserved word 'import' went through steps: 1. clear watchman watches. Unexpected use of reserved word 'import'经历了以下步骤:1.清除看守手表。 2. re-yarn all node modules 3. reset Metro Bundler Cache 4. Remove haste cache. 2.重新学习所有节点模块3.重置Metro Bundler缓存4.删除急速缓存。

I've also deleted my .babelrc file because RN supposedly bundles the correct babel settings. 我还删除了.babelrc文件,因为RN可能捆绑了正确的babel设置。

On Android emulator i get unable to resolve module babel-polyfill . 在Android模拟器上,我unable to resolve module babel-polyfill

On Xcode / Simulator i also get unable to resolve module babel-polyfill from project's index.js 在Xcode / Simulator上,我也unable to resolve module babel-polyfill从项目的index.js unable to resolve module babel-polyfill

At my wit's end here. 我的机智到此为止。 Tried uninstalling various incarnations of babel. 尝试卸载Babel的各种化身。

Versions: RN v0.55.4 版本:RN v0.55.4

i still have pkg json dev dependency of: 我仍然有pkg json dev依赖项:

"metro-react-native-babel-preset": "^0.50.0"

but i think thats default wrapped in RN so kind of moot. 但是我认为那是默认包装在RN中的,所以没有任何争议。

What am i missing and is there a sane way of setting Babel for RN projects? 我缺少什么,有没有一种合理的方法来为RN项目设置Babel?

yes it was an import of the babel polyfill, but do you know the explanation to this? 是的,这是通天塔粉填料的进口,但是您知道对此的解释吗?

it is because you are writing ES6 code but import hasn't been yet totally added to it so polyfill transforms this to CommonJS, interesting isn't it? 这是因为您正在编写ES6代码,但尚未完全添加导入功能,因此polyfill将其转换为CommonJS,不是吗? in the future it is predicted that you wont need it anymore since it will be implemented 100% 预计将来您将不再需要它,因为它将100%实施

Ended up being an import of the babelpolyfill module i'd left uncommented-out in the index.js file. 最终导入了babelpolyfill模块,我在index.js文件中未加注释。

Totally ditzy by me. 我完全呆住了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM