React Native: Can't find variable: require

自作多情 提交于 2021-01-27 20:51:09

问题


I am trying to modify a react native boilerplate so that I can be run on Android platform.

I installed the expo package and added an index.js file on the root directory. But when I run the android code, it raised Can't find variable: require on the bundling phase

I uploaded my code here. Does anyone have an idea what I missed here?


回答1:


resetting the cache worked for me.

On expo

expo r -c

for pure react native

react-native start --reset-cache




回答2:


For those whose cache clearing didn't work. Try deleting .bablerc file. 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 .

Platforms:

expo react native react native web




回答3:


You should import your server.default in es6 style. require is a node.js method, in es6 modules you should use import instead. See here for more info on the usage of import.

Here you did

 const newApp = require('./server').default;

When you should have

import {default} from './server'


来源:https://stackoverflow.com/questions/52280692/react-native-cant-find-variable-require

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!