React Native [错误无法运行 jetifier。]

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

当我尝试使用此 cmd 在模拟器中运行发布 APK 时:

npx react-native run-android --variant=release

它给了我这样的错误:

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
node:internal/fs/utils:348
    throw err;
    ^

Error: ENOENT: no such file or directory, scandir 'node_modules'
    at readdirSync (node:fs:1451:3)
    at readDir (C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\jetifier\src\utils.js:14:17)
    at Object.<anonymous> (C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\jetifier\index.js:12:15)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\jetifier\bin\jetify:3:1) {
  errno: -4058,
  syscall: 'scandir',
  code: 'ENOENT',
  path: 'node_modules'
}

Node.js v18.13.0
error Failed to run jetifier.
Error: Command failed: C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\jetifier\bin\jetify
    at makeError (C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:174:9)
    at C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\@react-native-community\cli-platform-android\node_modules\execa\index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.runAndroid [as func] (C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:104:7)
    at async Command.handleAction (C:\Users\sapar\OneDrive\Desktop\Project\ReactNative\TextUtils\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.

Android -> gradle.properties

android.useAndroidX=true
android.enableJetifier=true

我将尝试将其添加到 gradle.properties 中的行,然后删除旧的节点模块文件夹并运行

npm i
并运行此 cmd
npx jetify
但仍然出现错误,

我不知道如何解决,有人可以帮助我吗?

android ios reactjs react-native apk
1个回答
0
投票

解决方案:

在根目录中运行此cmd,

npm install --save-dev jetifier --force

那么,

npx jetify

那么,

npm start --reset-cache

最后运行这个cmd,

npx react-native run-android --variant=release

这对我有用!

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