vue webpack模板缺少解析器

Sab*_*ran 40 webpack vue.js prettier

我只是使用webpack模板设置一个vue项目,如下所示:http://vuejs-templates.github.io/webpack/

但是在运行npm run dev之后只是为了测试模板是否正常工作,我得到了这个错误:

Failed to compile with 2 errors                                                                                                                                                                                                                                                           21:49:02
 error  in ./src/App.vue

Module build failed: Error: No parser and no file path given, couldn't infer a parser.
    at normalize (path\node_modules\prettier\index.js:7051:13)
    at formatWithCursor (path\node_modules\prettier\index.js:10370:12)
    at path\node_modules\prettier\index.js:31115:15
    at Object.format (path\node_modules\prettier\index.js:31134:12)
    at Object.module.exports (path\node_modules\vue-loader\lib\template-compiler\index.js:80:23)

 @ ./src/App.vue 11:0-354
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

 error  in ./src/components/HelloWorld.vue

Module build failed: Error: No parser and no file path given, couldn't infer a parser.
    at normalize (path\node_modules\prettier\index.js:7051:13)
    at formatWithCursor (path\node_modules\prettier\index.js:10370:12)
    at path\node_modules\prettier\index.js:31115:15
    at Object.format (path\node_modules\prettier\index.js:31134:12)
    at Object.module.exports (path\node_modules\vue-loader\lib\template-compiler\index.js:80:23)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Jes*_*lam 84

Prettier1.13.0今天发生的更新中引起了这种倒退.降级到以前的版本以修复此错误:

npm install --save-dev prettier@1.12.0

npm run dev

这应该够了吧.

  • 使用Yarn对我不起作用:( (9认同)
  • 这适合我!哇,1个包的一个坏更新,整个项目中断了.这是javascript格局的当前状态 (2认同)

Yov*_*var 7

如果您正在使用Yarn,请将此添加到您package.json的强制@vue/component-compiler-utils使用正确的版本:

"resolutions": {
  "@vue/component-compiler-utils/prettier": "1.12.1"
}
Run Code Online (Sandbox Code Playgroud)

然后重新安装.

参考


pmb*_*ugo 6

它在vue-loader@13.7.2和vue-loader@14.2.3中修复.所以只需升级.