需要帮助解决使用 Ubuntu 机器时出现的奇怪构建失败问题

需要帮助解决使用 Ubuntu 机器时出现的奇怪构建失败问题

我最好的猜测是机器上有东西损坏了,但我还没有弄清楚是什么。该机器正在运行 Ubuntu 22.04。这个问题很容易重现:

yarn create vite my-vue-app --template vue
cd my-vue-app
yarn add cesium vite-plugin-cesium vite -D

更新vite.config.js至:

// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import cesium from 'vite-plugin-cesium'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), cesium()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  }
})

在 HelloWorld.vue 中,使用以下命令导入 cesiumimport * as Cesium from 'cesium'

然后运行yarn dev,会出现以下错误:

✘ [ERROR] Failed to resolve entry for package "https". The package may have incorrect main/module/exports specified in its package.json. [plugin vite:dep-pre-bundle]

    node_modules/esbuild/lib/main.js:1373:21:
      1373 │         let result = await callback({
           ╵                      ^

    at packageEntryFailure (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28725:11)
    at resolvePackageEntry (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28722:5)
    at tryNodeResolve (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28453:20)
    at Context.resolveId (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:28212:28)
    at Object.resolveId (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:44276:64)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:65922:21
    at async file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:39976:34
    at async requestCallbacks.on-resolve (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:1373:22)
    at async handleRequest (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:729:13)


  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1292:20:
      1292 │       let promise = setup({
           ╵                     ^

    at setup (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:39956:19)
    at handlePlugins (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:1292:21)
    at buildOrContextImpl (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:978:5)
    at Object.buildOrContext (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:786:5)
    at /home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:2186:68
    at new Promise (<anonymous>)
    at Object.context (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:2186:27)
    at Object.context (/home/me/projects/test/my-vue-app/node_modules/esbuild/lib/main.js:2026:58)
    at prepareEsbuildOptimizerRun (file:///home/me/projects/test/my-vue-app/node_modules/vite/dist/node/chunks/dep-bb8a8339.js:46041:35)

  The plugin "vite:dep-pre-bundle" was triggered by this import

    node_modules/@cesium/engine/Source/Core/Resource.js:2076:48:
      2076 │       return URL.protocol === "https:" ? import("https") : import("http");
           ╵                                                 ~~~~~~~

奇怪的是,我可以使用 VirtualBox 在虚拟机中安装全新的 Ubuntu,并且一切都会按预期工作。

此外,在 MacOS 上尝试此操作也是可行的。

我需要这个简单的示例项目在我的计算机上构建和运行。它不会。例如,如果我在虚拟机内设置一个全新的 Ubuntu 安装,它就会运行。我不知道虚拟机和我的机器有什么区别。它们的配置相同

如果有人对可能出现的问题、需要检查的事情或需要尝试的事情有任何想法,请告诉我。

相关内容