You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue3+CesiumJS+Webpack项目模块找不到错误修复咨询

问题:Vue集成CesiumJS构建失败,缺少Node核心模块解析

项目背景

我有一个可复现问题的示例项目,创建步骤如下:

    1. vue create vueces
    1. 删除项目中不必要的文件
    1. yarn add cesium

关键组件代码(HelloWorld.vue)

<template>
  <div ref="cesiumContainer" id="cesiumContainer">
    hello
  </div>
</template>

<script setup>
import { Viewer } from "cesium";
import "cesium/Build/Cesium/Widgets/widgets.css";

const viewer = new Viewer("cesiumContainer");

console.log("viewer", viewer);
</script>

<style scoped>
</style>

构建错误信息

Module not found: Error: Can't resolve 'url' in '/Users/eric/depot/tmp/vueces/node_modules/@cesium/engine/Source/Core'
Module not found: Error: Can't resolve 'zlib' in '/Users/eric/depot/tmp/vueces/node_modules/@cesium/engine/Source/Core'
Module not found: Error: Can't resolve 'https' in '/Users/eric/depot/tmp/vueces/node_modules/@cesium/engine/Source/Core'
Module not found: Error: Can't resolve 'http' in '/Users/eric/depot/tmp/vueces/node_modules/@cesium/engine/Source/Core'

错误提示说明:

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }

已尝试的解决方案

我添加了webpack.config.js,内容如下:

module.exports = function (webpackEnv) {
  return {
    resolve: {
      fallback: {
        url: false,
        zlib: false,
        https: false,
        http: false,
      }
    }
  }
}

但错误仍然存在。

疑问

  1. 需要修改什么才能让项目正常构建?
  2. 这些模块(url、zlib、https、http)是CesiumJS必需的吗?

内容的提问来源于stack exchange,提问作者Eric G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:52:34