当我使用vue时-cli@3到

npm run build

系统提示生成此错误No module factory available for dependency type: CssDependency

我搜索了很多相关的问题,但它们都是有Angular 的,我也try 过

  1. rm-r node _模块
  2. rm包裹锁.json
  3. npm i

但这个错误仍然存在,我想知道如何解决这个问题

以下是我的错误细节

ERROR  Error: No module factory available for dependency type: CssDependency
Error: No module factory available for dependency type: CssDependency
    at addDependency (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:800:12)
    at iterationOfArrayCallback (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:208:3)
    at addDependenciesBlock (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:816:5)
    at Compilation.processModuleDependencies (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:827:4)
    at afterBuild (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:954:15)
    at buildModule.err (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:998:11)
    at callback (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:734:5)
    at module.build.error (E:\Games\hitokoto\node_modules\webpack\lib\Compilation.js:782:12)
    at handleParseResult (E:\Games\hitokoto\node_modules\webpack\lib\NormalModule.js:478:12)
    at doBuild.err (E:\Games\hitokoto\node_modules\webpack\lib\NormalModule.js:500:6)
    at runLoaders (E:\Games\hitokoto\node_modules\webpack\lib\NormalModule.js:358:12)
    at E:\Games\hitokoto\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (E:\Games\hitokoto\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at E:\Games\hitokoto\node_modules\loader-runner\lib\LoaderRunner.js:186:6
    at context.callback (E:\Games\hitokoto\node_modules\loader-runner\lib\LoaderRunner.js:111:13)
    at childCompiler.runAsChild (E:\Games\Hitokoto\node_modules\mini-css-extract-plugin\dist\loader.js:198:12)
    at compile (E:\Games\hitokoto\node_modules\webpack\lib\Compiler.js:343:11)
    at hooks.afterCompile.callAsync.err (E:\Games\hitokoto\node_modules\webpack\lib\Compiler.js:681:15)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (E:\Games\hitokoto\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (E:\Games\hitokoto\node_modules\tapable\lib\Hook.js:154:20)
    at compilation.seal.err (E:\Games\hitokoto\node_modules\webpack\lib\Compiler.js:678:31)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (E:\Games\hitokoto\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
E:\Games\hitokoto\node_modules\neo-async\async.js:16
    throw new Error('Callback was already called.');

下面是我的Package.json文件

{
  "name": "hitokoto",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.4.4",
    "jquery": "^3.4.1",
    "jquery-ui": "^1.12.1",
    "vue": "^2.6.10",
    "vue-router": "^3.1.3"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.1.0",
    "@vue/cli-plugin-eslint": "^4.1.0",
    "@vue/cli-plugin-router": "^4.1.0",
    "@vue/cli-service": "^4.1.0",
    "@vue/eslint-config-prettier": "^5.0.0",
    "babel-eslint": "^10.0.3",
    "eslint": "^5.16.0",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-vue": "^5.0.0",
    "prettier": "^1.19.1",
    "stylus": "^0.54.7",
    "stylus-loader": "^3.0.2",
    "vue-template-compiler": "^2.6.10"
  }
}

推荐答案

我也有同样的问题,在运行npm run build命令时发现它与upper/lower casing of the path used有关.

使用Powershell或cmd,我做到了:

C:\> cd C:\git\testing
C:\git\testing> npm run build

和你犯了同样的错误.

然后我做了这个(注意大写GIT):

C:\>cd C:\GIT\testing
C:\GIT\testing> npm run build

然后它成功了.我在Windows 10上.

Vue.js相关问答推荐

如何在 Vuetify 2 中的轮播项目上放置 href 属性?

VueJS 中的 VisJS 时间轴:带有图像的项目放错了位置

vuetify/mdi 不显示图标

如何使用 async/await 在 vue js 中添加标头

vuejs中watch方法和计算方法有什么区别

CLI 3 - 如何为 CSS/Sass 创建vendor bundle ?

Polyfill for ie

将自定义部分添加到 v-autocomplete 下拉列表

使用vue.js单击时如何获取按钮的值

使用props向组件添加类名

异步方法不等待函数

如何将 git hash 添加到 Vue.js 组件

使用 refs 聚焦元素目标

vue-cli-service build --target lib 导入为 lib 时丢失图像路径

找不到模块 'babel-core' 但已安装 @babel/core

将 ref 的内容从子组件传递到另一个 VueJS 子组件

更改时(change)调用函数

Bootstrap-vue:如何将数据传递给模态?

Vue $refs 对象的类型为 unknown未知

Vuetify 过渡:如何设置过渡速度