[英]React Native: Can't find variable: require
I am trying to modify a react native boilerplate so that I can be run on Android platform. 我正在尝试修改React本机样板,以便可以在Android平台上运行。
I installed the expo package and added an index.js file on the root directory. 我安装了expo软件包,并在根目录上添加了index.js文件。 But when I run the android code, it raised Can't find variable: require
on the bundling phase 但是当我运行android代码时,它引发了Can't find variable: require
在捆绑阶段Can't find variable: require
I uploaded my code here . 我在这里上传了代码。 Does anyone have an idea what I missed here? 有人知道我在这里错过了什么吗?
resetting the cache worked for me. 重置缓存对我有用。
On expo 博览会上
expo r -c 展览会
for pure react native 对于纯天然反应
react-native start --reset-cache react-native开始--reset-cache
For those whose cache clearing didn't work. 对于那些清除缓存不起作用的用户。 Try deleting .bablerc file . 尝试删除.bablerc文件 。 It has its own ways of effecting cache. 它具有影响缓存的自己的方式。 My issue was only resolved after i deleted this. 我的问题只有在删除后才能解决。 I came across this when i was porting my react native app to web using react-native-web . 当我使用react-native-web将我的本机应用程序移植到Web时遇到了这个问题。
Platforms: 平台:
expo react native react native web 世博反应本地反应本地网站
You should import your server.default in es6 style. 您应该以es6样式导入server.default。 require
is a node.js
method, in es6 modules you should use import
instead. require
是一个node.js
方法,在es6模块中,应改为使用import
。 See here for more info on the usage of import
. 有关import
用法的更多信息,请参见此处 。
Here you did 在这里你做了
const newApp = require('./server').default;
When you should have 什么时候应该有
import {default} from './server'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.