prettier remove default parser breaks the tool
In prettier 1.13.0, default parser was removed with a minor version(used to be babylon), this breaks the formatter here.
https://github.com/vuejs/component-compiler-utils/blob/8a8a95c84dc2f3f14625e31805f975d11a898990/lib/compileTemplate.ts#L161
Issue has been created in prettier repo as well, attached here for tracking purpose. https://github.com/prettier/prettier/issues/4567
Adding error stack info below for our friend Google to route new comers to:
ERROR in ./src/client/components/Com1.vue?vue&type=template&id=22d07c36 (../happy-cli/node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../happy-cli/node_modules/vue-loader/lib??vue-loader-options!./src/client/components/Com1.vue?vue&type=template&id=22d07c36)
Module build failed: Error: No parser and no file path given, couldn't infer a parser.
at normalize ({project_dir}/node_modules/prettier/index.js:7051:13)
at formatWithCursor ({project_dir}/node_modules/prettier/index.js:10370:12)
at {project_dir}/node_modules/prettier/index.js:31115:15
at Object.format ({project_dir}/node_modules/prettier/index.js:31134:12)
at actuallyCompile ({project_dir}/node_modules/@vue/component-compiler-utils/dist/compileTemplate.js:93:29)
at compileTemplate ({project_dir}/node_modules/@vue/component-compiler-utils/dist/compileTemplate.js:26:16)
at Object.module.exports ({project_dir}/node_modules/vue-loader/lib/loaders/templateLoader.js:42:20)
PR: https://github.com/vuejs/component-compiler-utils/pull/15
Damn. Just decided to try the vue-cli out and ended up with the no parser error on a newly init'ed project. I was at a complete loss, but managed to find my way to the prettier breaking change. Good job finding a solution this quick and thanks, implemented this locally. 👍
in ./src/App.vue
Module build failed: Error: No parser and no file path given, couldn't infer a parser. at normalize (/Users/lanc/Desktop/runbuild/node_modules/[email protected]@prettier/index.js:7051:13) at formatWithCursor (/Users/lanc/Desktop/runbuild/node_modules/[email protected]@prettier/index.js:10370:12) at /Users/lanc/Desktop/runbuild/node_modules/[email protected]@prettier/index.js:31115:15 at Object.format (/Users/lanc/Desktop/runbuild/node_modules/[email protected]@prettier/index.js:31134:12) at Object.module.exports (/Users/lanc/Desktop/runbuild/node_modules/[email protected]@vue-loader/lib/template-compiler/index.js:80:23)
@ ./src/App.vue 11:0-392 @ ./src/main.js @ multi ./node_modules/[email protected]@webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
How to solve this?
as a workaround, in your package.json, force prettier to be 1.12 with
npm install prettier@~1.12.1 .
UPDATE: NO need to do downgrade prettier version now, this was working as workaround before release of @vue/component-compiler-utils 1.3.1
If you have applied downgrade above, remove it from pacakge.json then run
npm update --depth=9999 @vue/component-compiler-utils
if havn't just run
npm update --depth=9999 @vue/component-compiler-utils
@pwang2 not work, still get 1.13.0
npm view prettier version
@lovemyliwu if you are using customized tools or npm link, it might be tricky and requires you to target the package tree correctly.
You might also need to regenerate you pacakge-lock.json or yarn.lock file.
Merged.
Thanks @yyx990803 ! We could expect a new version of @vue/component-compiler-utils soon.
Released in 1.3.1
remove node_modules and reinstall everything.
还是不行啊,尤大婶
rm -rf package-lock.json node_modules
npm install
rm -rf node_modules
npm install
npm install prettier@~1.12.1
rm -rf node_modules
npm install
npm install prettier@~1.12.1
亲测有效,谢谢~
nuxtjs still doesn't work.... The same error with prettier
you can try cd node_modules/ rm -rf [email protected]@prettier cnpm install prettier@~1.12.1
(if your node_modules/ have [email protected]@prettier )
@lanxin1234 no need install prettier-1.12.x. use npm replace cnpm, or wait taobao update component-compiler-utils-1.3.0 to 1.3.1
此问题尤大已经解决,无需降级prettier。删掉node_modules,yarn.lock, package-lock.json 等文件,再拉取一次package就行。淘宝镜像同步稍晚了一会,现在也已经ok了。
Yarn and npm registries are still pointing to 1.13.0, not 1.13.1.
@lanxin1234 it work with this manual install.
@transtone only [email protected] has this error. It use [email protected]. But [email protected] is the newest stable version....
@lanxin1234 是的,需要删掉,我是这样写的,成功了,感谢
rm -rf node_modules
cnpm cache verify
cnpm i
rm -rf node_modules/[email protected]@prettier
cnpm install --save-dev [email protected]
上面的方法都试了,还是报错