React-Native 0.57:“找不到变量:要求",带有Metro-react-native-babel-preset [英] React-Native 0.57: 'Can't find variable: require' with metro-react-native-babel-preset

查看:332
本文介绍了React-Native 0.57:“找不到变量:要求",带有Metro-react-native-babel-preset的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了一个多平台项目,其中在react-native和react-js之间共享代码. 所以我有一个用于浏览器/电子的webpack设置,和一个用于Android/iOS的react-native 0.57设置. 我现在遇到的问题如下: 找不到变量:要求

I started a multiplatform project with code sharing between react-native and react-js. So I have a webpack setup for browser/Electron, and a react-native 0.57 setup for Android/iOS. The problem I'm having right now is the following: Can't find variable: require

这可能是一个非常秃顶的问题,但是我还需要其他吗?我读到,React-native应该自己支持require,但是还找不到与此设置有关的任何内容.

It might be a very bald question, but do I need anything else? I read, that React-native should support require by itself, but couldn't find anything related to this setup yet.

.babelrc {"presets": ["module:metro-react-native-babel-preset"]}

.babelrc {"presets": ["module:metro-react-native-babel-preset"]}

我还在浏览器端使用@ babel/polyfill和@ babel/runtime,但我想知道它们是否会干扰.

I'm also using @babel/polyfill and @babel/runtime on browser side, but I wonder if they would interfere.

推荐答案

解决了这个问题,我的.babelrc可以,但是打包程序缓存了第一个错误的代码,因此我必须以如下方式启动打包程序: react-native start --reset-cache

Got the solution, my .babelrc was okay, but the packager cached the very first wrong one so I had to start the packager as: react-native start --reset-cache

这篇关于React-Native 0.57:“找不到变量:要求",带有Metro-react-native-babel-preset的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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