不支持 require(),使用所有 CommonJS 模块中都可用的动态 import()

问题描述 投票:0回答:2

我有一个 SDK 47 的项目,Play 商店已停止接受,我发现自己处于更新项目的境地。

我尝试更新 SDK 48 但没有成功,经过几次尝试后,我决定使用 SDK 49 创建一个新的 expo 项目,并小心地将文件和配置从旧项目移动到新项目。解决 bug、错误和依赖版本后,项目运行没有问题。 🙂 认为通过使用 SDK 49 的项目就可以解决我所有的问题,我为 Android 构建了一个版本,当我将其上传到 Play 商店时,我发现了同样的问题。

应用程序必须面向 Android 13(API 级别 33)或更高版本 😦

我做了一个 npx expo-doctor@latest 并发现 @isaacs/cliui 依赖项存在问题,在解决它之后(或者我认为是这样),构建失败,说wrap-ansi 依赖项存在问题。

/Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/doctor/dependencies/ensureDependenciesAsync.js:9
var _wrapAnsi = _interopRequireDefault(require("wrap-ansi"));
                                       ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/wrap-ansi/index.js from /Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/doctor/dependencies/ensureDependenciesAsync.js not supported.
Instead change the require of index.js in /Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/doctor/dependencies/ensureDependenciesAsync.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/doctor/dependencies/ensureDependenciesAsync.js:9:40)
    at Object.<anonymous> (/Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/doctor/web/WebSupportProjectPrerequisite.js:12:32)
    at Object.<anonymous> (/Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/startAsync.js:16:38)
    at /Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/index.js:117:40
    at async expoStart (/Users/marcos/Proyectos/GorilaST/Clientes/zizvio/zizvio-app/node_modules/@expo/cli/build/src/start/index.js:116:29) {
  code: 'ERR_REQUIRE_ESM'
}

我已经尝试了在互联网上找到的所有内容,但无法让构建通过。

我给你一些我所做的操作,它们的结果和配置文件。

  • npx expo-doctor@最新

结果

✔ 检查 Expo 配置中的常见问题 ✔ 检查 package.json 中的常见问题 ✔ 检查不应该直接安装的软件包的依赖关系 ✔ 检查常见的项目设置问题 ✔ 检查 Expo 配置 (app.json/ app.config.js) 架构 ✔ 检查 npm/yarn 版本 ✔ 检查软件包是否与已安装的 Expo SDK 所需的版本匹配 ✔ 检查本地安装的旧版全局 CLI ✔ 检查本机模块是否未使用不兼容的支持包 ✔ 检查本机模块是否使用与已安装的 Expo SDK 兼容的支持包版本

未发现该项目有任何问题!

  • 纱线列表 --pattern wrap-ansi 结果
yarn list v1.22.19
├─ [email protected]
└─ [email protected]
✨  Done in 0.60s.
  • package.json
{
  "name": "zizvio-app",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@isaacs/cliui": "^8.0.2",
    "@react-native-async-storage/async-storage": "1.18.2",
    "@react-native-community/datetimepicker": "7.2.0",
    "@react-native-community/netinfo": "9.3.10",
    "@react-navigation/bottom-tabs": "^6.2.0",
    "@react-navigation/native": "^6.0.8",
    "@react-navigation/native-stack": "^6.4.1",
    "axios": "^0.25.0",
    "expo": "~49.0.15",
    "expo-app-loading": "~2.1.1",
    "expo-application": "~5.3.0",
    "expo-auth-session": "~5.0.2",
    "expo-build-properties": "~0.8.3",
    "expo-checkbox": "~2.4.0",
    "expo-dev-client": "~2.4.12",
    "expo-device": "~5.4.0",
    "expo-font": "~11.4.0",
    "expo-linking": "~5.0.2",
    "expo-notifications": "~0.20.1",
    "expo-radio-button": "^1.0.8",
    "expo-random": "~13.2.0",
    "expo-secure-store": "~12.3.1",
    "expo-status-bar": "~1.6.0",
    "expo-updates": "~0.18.19",
    "expo-web-browser": "~12.3.2",
    "formik": "^2.2.9",
    "intl": "^1.2.5",
    "jwt-decode": "^3.1.2",
    "lodash": "^4.17.21",
    "luxon": "^3.4.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.72.6",
    "react-native-dotenv": "^3.3.1",
    "react-native-dropdown-picker": "^5.3.0",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-maps": "1.7.1",
    "react-native-modal": "^13.0.0",
    "react-native-modal-datetime-picker": "^13.1.0",
    "react-native-root-toast": "^3.3.0",
    "react-native-safe-area-context": "4.6.3",
    "react-native-screens": "~3.22.0",
    "react-native-svg": "13.9.0",
    "react-native-uuid": "^2.0.1",
    "react-native-web": "~0.19.6",
    "react-navigation": "^4.4.4",
    "uuid": "^8.3.2",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^4.0.0",
    "eslint-plugin-promise": "^6.0.0",
    "eslint-plugin-react": "^7.28.0",
    "eslint-plugin-react-native": "^4.0.0",
    "prettier": "^2.5.1"
  },
  "resolutions": {
    "@expo/config-plugins": "~7.2.2",
    "@expo/prebuild-config": "~6.2.4",
    "wrap-ansi": "^8.1.0"
  },
  "private": true
}
  • app.json
{
  "expo": {
    "name": "zizvio",
    "slug": "zizvio",
    "privacy": "unlisted",
    "version": "1.1.58",
    "scheme": "zizvio",
    "orientation": "portrait",
    "icon": "./src/assets/icon.png",
    "splash": {
      "image": "./src/assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.zizvio.zizvio1",
      "buildNumber": "1.0.44",
      "config": {
        "googleMapsApiKey": "**********FOPREDFGdfgWhP-N4KxcImioKkRtjBmxx9Rwo"
      },
      "infoPlist": {
        "NSLocationWhenInUseUsageDescription": "Esta app puede necesitar tu ubicación para realizar la entrega de los pedidos."
      }
    },
    "android": {
      "versionCode": 72,
      "adaptiveIcon": {
        "foregroundImage": "./src/assets/adaptive-icon.png",
        "backgroundColor": "#FFFFFF"
      },
      "package": "com.zizvio.zizvio",
      "config": {
        "googleMaps": {
          "apiKey": "**********FOPREDFGdfgWhP-N4KxcImioKkRtjBmxx9Rwo"
        }
      },
      "googleServicesFile": "./google-services.json"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "owner": "zizvio",
    "extra": {
      "eas": {
        "projectId": "********-5ed5-****-34ft-756975a8e09p"
      }
    },
    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "compileSdkVersion": 33,
            "targetSdkVersion": 33,
            "minSdkVersion": 33,
            "buildToolsVersion": "33.0.0"
          }
        }
      ]
    ]
  }
}

我已经处理了好几天了,这是非常明显的事情,但我还没有找到它,我已经筋疲力尽,没有办法解决它。

我需要尽快上传到Play商店。

我会细心回复并测试每一个建议或想法。

如有任何帮助,我们将不胜感激。我等待你的答复。谢谢你。

android react-native build expo
2个回答
0
投票

所以这对我有用! (我建议将代码备份到 Github 以撤消升级过程中的任何更改。)

yarn cache clean

然后

yarn install

然后

yarn upgrade

然后一切都应该正常。


0
投票

这里也一样,任何帮助也很感激

© www.soinside.com 2019 - 2024. All rights reserved.