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

Angular 9升级至10时执行ng update报错:找不到node:fs模块

Angular 9升级到10时执行ng update报错:Cannot find module 'node:fs'

问题场景

尝试将Angular从9版本升级至10版本,执行ng update命令时操作失败,核心报错为Error: Cannot find module 'node:fs'。

完整报错信息

PS C:> ng update
已安装的本地Angular CLI版本低于最新稳定版本。
正在安装临时版本以执行更新。
通过npm安装工具包。
已通过npm安装工具包。
检测到Node.js版本v13.10.1。
奇数版本的Node.js不会进入LTS状态,不应用于生产环境。
(node:29136) ExperimentalWarning: The ESM module loader is experimental.
未知错误:Error: Cannot find module 'node:fs'

已尝试无效操作

  • 执行npm install node:fs,提示该模块不存在
  • 尝试安装node-fs、fs模块,问题未解决

环境版本信息

包名版本号
@angular-devkit/architect0.901.15
@angular-devkit/build-angular0.901.15
@angular-devkit/build-optimizer0.901.15
@angular-devkit/build-webpack0.901.15
@angular-devkit/core9.1.15
@angular-devkit/schematics9.1.15
@angular/cdk9.2.4
@angular/cli9.1.15
@angular/http7.2.16
@angular/material9.2.4
@ngtools/webpack9.1.15
@schematics/angular9.1.15
@schematics/update0.901.15
rxjs6.5.5
typescript3.8.3
webpack4.42.0

解决方案

  1. 升级Node.js至兼容LTS版本
    node:fs这种模块导入语法是Node.js 14.13.0及以上版本才支持的,而当前使用的v13.10.1是非LTS版本,同时Angular 10要求Node.js最低版本为12.x LTS。建议升级到Node.js 12.x或14.x LTS版本后,重新执行升级命令。

  2. 指定Angular CLI 10版本执行升级
    避免临时安装的CLI版本与Node.js版本不兼容,直接使用指定版本的CLI执行升级:

    npx @angular/cli@10 update @angular/core@10 @angular/cli@10
    
  3. 清理依赖缓存后重试
    清理npm缓存并重新安装依赖,避免缓存导致的冲突:

    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 08:45:24