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/architect | 0.901.15 |
| @angular-devkit/build-angular | 0.901.15 |
| @angular-devkit/build-optimizer | 0.901.15 |
| @angular-devkit/build-webpack | 0.901.15 |
| @angular-devkit/core | 9.1.15 |
| @angular-devkit/schematics | 9.1.15 |
| @angular/cdk | 9.2.4 |
| @angular/cli | 9.1.15 |
| @angular/http | 7.2.16 |
| @angular/material | 9.2.4 |
| @ngtools/webpack | 9.1.15 |
| @schematics/angular | 9.1.15 |
| @schematics/update | 0.901.15 |
| rxjs | 6.5.5 |
| typescript | 3.8.3 |
| webpack | 4.42.0 |
解决方案
升级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版本后,重新执行升级命令。指定Angular CLI 10版本执行升级
避免临时安装的CLI版本与Node.js版本不兼容,直接使用指定版本的CLI执行升级:npx @angular/cli@10 update @angular/core@10 @angular/cli@10清理依赖缓存后重试
清理npm缓存并重新安装依赖,避免缓存导致的冲突:npm cache clean --force rm -rf node_modules package-lock.json npm install
内容的提问来源于stack exchange,提问作者Programmer1
相关产品推荐
相关产品推荐

