首页 > 解决方案 > Nativescript 错误:执行 webpack 失败,退出代码为 1

问题描述

我已经按照说明(来自https://docs.nativescript.org/environment-setup.html#macos-ios )在新的 iMac(运行 Big Sur)上完成了 Nativescript 的全新安装。

昨天安装后运行良好,但今天我无法在 ios 模拟器(或 Android 虚拟设备)中运行应用程序。

终端中的ns doctor命令最初给了我这个:

No issues were detected.
✔ Your ANDROID_HOME environment variable is set and points to correct directory.
✔ Your adb from the Android SDK is correctly installed.
✔ The Android SDK is installed.
✔ A compatible Android SDK for compilation is found.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Xcode is installed and is configured properly.
✔ xcodeproj is installed and is configured properly.
✔ CocoaPods are installed.
✔ CocoaPods update is not required.
✔ CocoaPods are configured properly.
✔ Your current CocoaPods version is newer than 1.0.0.
✔ Python installed and configured correctly.
✔ The Python 'six' package is found.
✔ Xcode version 12.5.1 satisfies minimum required version 10.
✔ Getting NativeScript components versions information...
✔ Component nativescript has 8.0.2 version and is up to date.

但是,当我创建一个新应用程序(ns create)然后尝试运行(ns run ios)时,我收到此错误:Executing webpack failed with exit code 1。

错误消息以此开头:TypeError: Cannot read property 'resolved' of undefined。

当我尝试在 Android 上运行它时,也会发生同样的事情。

在尝试在 ios 和 Android 上运行它之后,ns doctor添加了这些行:

✔ Component @nativescript/core has 8.0.8 version and is up to date.
✔ Component @nativescript/ios has 8.0.0 version and is up to date.
✔ Component @nativescript/android has 8.0.0 version and is up to date.

所以看起来平台正在被正确添加。

任何帮助将不胜感激!

完整的错误信息是:

Searching for devices...
Preparing project...
webpack is watching the files...
/Users/student/Desktop/testApp/node_modules/webpack/lib/FileSystemInfo.js:817
    if (entry.resolved !== undefined) return entry.resolved;
              ^

TypeError: Cannot read property 'resolved' of undefined
    at getResolvedTimestamp (/Users/student/Desktop/testApp/node_modules/webpack/lib/FileSystemInfo.js:817:12)
    at /Users/student/Desktop/testApp/node_modules/webpack/lib/FileSystemInfo.js:1167:21
    at /Users/student/Desktop/testApp/node_modules/webpack/lib/util/AsyncQueue.js:352:5
    at Hook.eval [as callAsync] (eval at create (/Users/student/Desktop/testApp/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/student/Desktop/testApp/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
    at AsyncQueue._handleResult (/Users/student/Desktop/testApp/node_modules/webpack/lib/util/AsyncQueue.js:322:21)
    at /Users/student/Desktop/testApp/node_modules/webpack/lib/util/AsyncQueue.js:305:11
    at /Users/student/Desktop/testApp/node_modules/webpack/lib/FileSystemInfo.js:3098:21
    at /Users/student/Desktop/testApp/node_modules/webpack/lib/FileSystemInfo.js:3010:22
    at /Users/student/Desktop/testApp/node_modules/neo-async/async.js:2830:7
    at done (/Users/student/Desktop/testApp/node_modules/neo-async/async.js:2925:13)
    at /Users/student/Desktop/testApp/node_modules/webpack/lib/FileSystemInfo.js:2994:23
    at Array.<anonymous> (/Users/student/Desktop/testApp/node_modules/webpack/lib/util/fs.js:311:21)
    at runCallbacks (/Users/student/Desktop/testApp/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)
    at /Users/student/Desktop/testApp/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:200:4
    at callback (/Users/student/Desktop/testApp/node_modules/graceful-fs/polyfills.js:299:20)
Executing webpack failed with exit code 1.

标签: nativescript

解决方案


感谢您报告此问题,我们已确认最新 webpack 版本中的重大更改: https ://github.com/webpack/webpack/releases/tag/v5.51.1

您现在可以切换您的 package.json 以使用rc以下方法来解决此问题:

"devDependencies": {
  ...
  "@nativescript/webpack": "rc"
},

然后ns clean,您现在应该可以运行您的应用程序了。

我们还发布了另一个beta将 webpack 固定到 5.50.0 的标签,因此ns clean在您自己的 package.json 中不进行任何其他依赖项更改的情况下现在也应该可以工作。


推荐阅读