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

安装@ng-idle/core时出现fsm.WriteStream is not a constructor错误求助

解决npm安装依赖时出现TypeError: fsm.WriteStream is not a constructor的问题

问题详情

执行命令npm install --save @ng-idle/core安装依赖时触发错误:

npm ERR! fsm.WriteStream is not a constructor 
npm ERR! Log files were not written due to an error writing to the directory: C:\Users\[username]\AppData\Local\npm-cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

添加--loglevel=verbose参数后得到详细错误日志:

npm info using npm@9.6.2
npm info using node@v20.8.1
npm verb title npm install @ng-idle/core
npm verb argv "install" "--save" "@ng-idle/core" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:C:\Users\[username]\AppData\Local\npm-cache\_logs\2023-10-14T22_27_32_906Z-
npm verb logfile could not be created: TypeError: fsMiniPass.WriteStreamSync is not a constructor
npm verb logfile no logfile created
npm verb shrinkwrap failed to load node_modules/.package-lock.json out of date, updated: node_modules/admin-lte
npm verb shrinkwrap failed to load node_modules/.package-lock.json out of date, updated: node_modules/admin-lte
npm verb stack TypeError: fsm.WriteStream is not a constructor
npm verb stack     at pipeToTmp (C:\Users\[username]\AppData\Roaming\npm\node_modules\npm\node_modules\cacache\lib\content\write.js:117:21)
npm verb stack     at handleContent (C:\Users\[username]\AppData\Roaming\npm\node_modules\npm\node_modules\cacache\lib\content\write.js:101:23)
npm verb cwd E:\[projectName]
npm verb Windows_NT 10.0.19045
npm verb node v20.8.1
npm verb npm  v9.6.2
npm ERR! fsm.WriteStream is not a constructor
npm verb exit 1
npm verb unfinished npm timer command:install 1697322452963
npm verb unfinished npm timer reify 1697322452967
npm verb unfinished npm timer reify:loadTrees 1697322453044
npm verb unfinished npm timer idealTree 1697322453045
npm verb unfinished npm timer idealTree:init 1697322453045
npm verb code 1

npm ERR! Log files were not written due to an error writing to the directory: C:\Users\[username]\AppData\Local\npm-cache\_logs
npm ERR! You can rerun the command with --loglevel=verbose to see the logs in your terminal

项目package.json内容:

{
  "name": "[project_name]",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^16.2.5",
    "@angular/common": "^16.2.5",
    "@angular/compiler": "^16.2.5",
    "@angular/core": "^16.2.5",
    "@angular/forms": "^16.2.5",
    "@angular/platform-browser": "^16.2.5",
    "@angular/platform-browser-dynamic": "^16.2.5",
    "@angular/router": "^16.2.5",
    "@ngrx/effects": "^16.2.0",
    "@ngrx/store": "^16.2.0",
    "@ngrx/store-devtools": "^16.2.0",
    "admin-lte": "^3.2.0",
    "jquery": "^3.7.1",
    "jspdf": "^2.5.1",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.2.2",
    "@angular/cli": "~16.2.2",
    "@angular/compiler-cli": "^16.2.5",
    "@types/jasmine": "~4.3.0",
    "@types/jquery": "^3.5.19",
    "jasmine-core": "~4.5.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~4.9.4"
  }
}

当前npm版本:

C:\Users\[username]>npm --v
9.6.2

解决方法

  • 强制清理npm缓存
    缓存损坏是触发该错误的常见原因,执行以下命令清理:

    npm cache clean --force
    
  • 重置项目依赖环境
    删除项目目录下的node_modules文件夹和package-lock.json文件,再重新安装基础依赖:

    # Windows系统
    rmdir /s /q node_modules && del package-lock.json
    # macOS/Linux系统
    rm -rf node_modules package-lock.json
    
    # 重新安装基础依赖
    npm install
    
  • 调整npm与Node.js版本兼容性
    当前使用的npm@9.6.2和Node.js@v20.8.1存在兼容性问题,建议升级npm到适配版本,或切换到Node.js 18.x LTS版本:

    # 升级npm到9.8.1版本
    npm install -g npm@9.8.1
    
  • 修复缓存目录权限
    错误提示无法写入缓存目录,检查C:\Users\[username]\AppData\Local\npm-cache的权限:

    1. 右键该文件夹,选择「属性」→「安全」
    2. 点击「编辑」,添加当前用户并授予「完全控制」权限
    3. 保存设置后重新执行安装命令
  • 重新安装目标依赖
    完成上述步骤后,再次执行安装命令:

    npm install --save @ng-idle/core
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 07:40:56