【问题标题】:node_modules/expo/AppEntry.js: Transformer.transform is not a functionnode_modules/expo/AppEntry.js:Transformer.transform 不是函数
【发布时间】:2020-07-19 11:10:21
【问题描述】:

我这几天一直在寻找解决这个问题的方法,我认为这与我升级到最新版本的世博会有关。我试过降级 SDK 和 expo 版本,删除我的 node_modules 和 package-lock 并重新安装。我已将 SourceExts 添加到我的 app.json 中。

任何帮助将不胜感激。该应用可在网络浏览器中运行,但不适用于 iO 或 android 模拟器。

app.json

{
  "expo": {
    "name": "GotThis",
    "slug": "GotThis",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "packagerOpts": {
      "sourceExts": ["js", "json", "ts", "tsx", "jsx"]
    }
  }
}

package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "test": "jest",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~38.0.8",
    "expo-status-bar": "^1.0.2",
    "react": "~16.11.0",
    "react-dom": "~16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    "react-native-elements": "^2.0.4",
    "react-native-paper": "^4.0.1",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.10.5",
    "babel-preset-expo": "^8.1.0",
    "jest-expo": "^38.0.2",
    "metro": "^0.60.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "react-test-renderer": "^16.13.1"
  },
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)"
    ]
  },
  "private": true
}

node_modules/expo/AppEntry.js

import registerRootComponent from 'expo/build/launch/registerRootComponent';

import App from '../../App';

registerRootComponent(App);

android 模拟器中的错误 android error

【问题讨论】:

    标签: react-native sdk react-native-android expo react-native-ios


    【解决方案1】:

    经过大量研究,我得出的结论是问题是由 metro-config 包的版本不匹配引起的。如果你在你的应用程序中依赖它来覆盖一些默认的 Metro 配置,你应该确保它与 react-native 依赖的版本相同。就我而言,我使用的是 metro@0.61.0,因为 react-native@0.62.2 依赖于 metro@0.58.0 我所做的只是将 Metro 版本从 @0.61.0 降级到 @0.58.0。

    您可以通过运行 npm ls metro-config 或搜索 package-lock.json 文件来检查需要和安装的版本。

    我已经关注了这个有用的thread,你可以看看这个解决方案是否不适合你。

    【讨论】:

    • 地铁如何降级?
    【解决方案2】:
    npm ls metro-config
    

    就我而言,我将metro 的版本从0.65.0 更改为0.56.4 并解决了这个问题。 ubuntu 在这里。

    【讨论】:

      【解决方案3】:

      @amo 给出了一个很好的方向。只是用详细信息扩展该答案:

      1. 通过运行npm ls metro-config 检查metro-config 依赖树。你应该得到类似这样的东西:
      npm ls metro-config   
      my_app@ /Users/home/my_app
      ├─┬ metro@0.66.2
      │ └── metro-config@0.66.2
      └─┬ react-native@0.63.2 invalid: "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz" from the root project
        └─┬ @react-native-community/cli@4.14.0
          ├─┬ metro-config@0.59.0
          │ └─┬ metro@0.59.0
          │   └── metro-config@0.59.0 deduped
          └─┬ metro@0.59.0
            └── metro-config@0.59.0 deduped
      
      1. 注意到 react-native 依赖于 metro-config 的 0.59.0 版本?运行npm install metro-config@0.59.0。这将安装并优先考虑 react-native 版本支持的版本。
      2. 删除 package.lock.json 文件和 node-modules 文件夹。
      3. 运行npm install
      4. 全部修复,开始你的应用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-25
        • 2020-07-17
        • 1970-01-01
        • 2021-06-24
        • 2021-11-30
        • 2022-08-06
        • 1970-01-01
        相关资源
        最近更新 更多