无法编译React Native Web

时间:2020-03-20 17:33:51

标签: react-native

我是本机反应的初学者。

我做了什么:

1)expo初始化newProj

2)选择空项目

3)expo start --web

4)选择在Android上运行

===========现在一切正常,正在编译===============

5)选择在Web浏览器上运行,然后出现此错误:

gcloud

这是我的App.js

WEB: Failed to compile
D:/ReactNative/newProj/node_modules/@unimodules/react-native-adapter/build/errors/CodedError.js
ReferenceError: D:\ReactNative\newProj\node_modules\@unimodules\react-native-adapter\build\errors\CodedError.js: Unknown helper createSuper

这是我的package.json

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  return (
    <View style={styles.container}>
      <Text>Hello World! </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

这是我的basel.config.js

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~36.0.0",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "babel-preset-expo": "~8.0.0",
    "@babel/core": "^7.0.0"
  },
  "private": true
}

这是CodeError.js

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

1 个答案:

答案 0 :(得分:2)

在我的项目中-根本没有反应-昨天开始出现相同的错误。它似乎与最近发布的babel-loader@8.1.0有关。

就我而言,它有助于将其版本固定为上一个版本8.0.6。

如果您使用的是yarn而不是npm,那么应该现在可以通过在package.json中添加一个resolutions字段来解决它。

首先,通过运行yarn why babel-loader确保项目中确实有babel-loader-它应该报告某些内容而不是什么。如果是这种情况,此解决方法应会有所帮助:

在package.json中,添加:

"resolutions:" {
    "babel-loader": "8.0.6"
}

接下来,删除您的node_modules 和yarn.lock ,然后再次再次运行yarn install