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

Windows 11下Node.js Vue项目无法运行,Vue CLI Service报错求助

问题描述

在Windows 11系统上运行代码库时遇到问题,Node版本为14.15.5,该项目在MacOS、Ubuntu系统及Heroku生产环境均可正常运行。控制台显示Node服务器已成功启动,能连接MongoDB和Redis,推测问题出在Vue(版本2.6.12)或Vue CLI。执行vue-cli-service serve时触发错误,已确认Node版本正确,也尝试过全局安装Vue CLI,求可能的原因。

错误日志:
错误日志截图

Vue package.json:

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "bundle-report": "webpack-bundle-analyzer --port 4200 dist/stats.json"
  },
  "dependencies": {
    "@ckeditor/ckeditor5-build-decoupled-document": "^18.0.0",
    "@ckeditor/ckeditor5-vue": "^1.0.3",
    "@fingerprintjs/fingerprintjs": "^3.3.2",
    "@fingerprintjs/fingerprintjs-pro": "^3.7.1",
    "@johmun/vue-tags-input": "^2.1.0",
    "@vue/composition-api": "^1.0.0-rc.3",
    "autolinker": "^3.14.2",
    "axios": "^0.21.1",
    "core-js": "^3.8.2",
    "date-fns": "^2.28.0",
    "detectrtc": "^1.4.1",
    "gsap": "^3.6.0",
    "imagekit-javascript": "^1.5.2",
    "imagekitio-vue": "^1.0.9",
    "ismobilejs": "^1.1.1",
    "just-detect-adblock": "^1.1.0",
    "jwt-decode": "^2.2.0",
    "maxlength-contenteditable": "^1.0.1",
    "socket.io-client": "^4.5.2",
    "timeme.js": "^2.1.0",
    "twilio-video": "^2.18.3",
    "v-hotkey": "^0.8.0",
    "vue": "^2.6.12",
    "vue-color": "^2.8.1",
    "vue-gtag": "^1.16.1",
    "vue-i18n": "^8.22.4",
    "vue-infinite-loading": "^2.4.5",
    "vue-router": "^3.4.9",
    "vue-select": "^3.18.3",
    "vue-smooth-dnd": "^0.8.1",
    "vue-vimeo-player": "^0.2.2",
    "vue-window-size": "^1.0.3",
    "vue-youtube": "^1.4.0",
    "vuejs-datepicker": "^1.6.2",
    "vuex": "^3.6.0",
    "webrtc-adapter-test": "^0.2.10"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.3.0",
    "@vue/cli-plugin-eslint": "~4.3.0",
    "@vue/cli-service": "~4.3.0",
    "babel-eslint": "^10.1.0",
    "dotenv-webpack": "^5.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "node-sass": "^4.14.1",
    "sass-loader": "^9.0.3",
    "vue-template-compiler": "^2.6.12",
    "webpack-bundle-analyzer": "^4.4.0"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}
可能的原因及解决方向

结合你的环境和配置,以下是几个大概率的问题点:

  • node-sass与Windows系统兼容性问题
    项目使用的node-sass@4.14.1依赖node-gyp编译,Windows环境下需要Python 2.7、Visual Studio Build Tools等配套环境,一旦缺失或版本不匹配就会触发编译失败。
    解决建议:要么安装完整的node-gyp依赖环境,要么将node-sass替换为dart-sass(sass-loader已支持,直接修改package.json依赖即可)。

  • Vue CLI全局与本地版本冲突
    你尝试了全局安装Vue CLI,但项目本地依赖的@vue/cli-service是~4.3.0,版本不一致可能导致命令执行异常。
    解决建议:优先使用项目本地的CLI服务,执行npx vue-cli-service serve代替直接运行vue-cli-service serve,避免全局版本干扰。

  • 文件路径大小写不匹配
    Windows系统大小写不敏感,但MacOS和Linux是敏感的。如果代码中引用路径的大小写和实际文件不一致(比如写了import './MyComponent'但实际文件是mycomponent.vue),在Windows上可能触发模块查找失败。
    解决建议:检查所有组件、资源的引用路径,确保和实际文件路径大小写完全一致。

  • 依赖缓存损坏
    Windows上的node_modules或锁文件可能出现损坏,导致依赖无法正常加载。
    解决建议:删除node_modules文件夹和package-lock.json,重新执行npm install,确保依赖完整安装。

  • 环境变量配置异常
    项目使用了dotenv-webpack,如果Windows上的.env文件格式错误、存在特殊字符或编码问题,可能导致编译出错。
    解决建议:检查.env文件的键值对格式,确保没有多余空格或特殊字符,同时确认文件编码为UTF-8。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 01:42:50