vuejs / component-compiler-utils

Lower level utilities for compiling Vue single file components
321 stars 75 forks source link

prettier remove default parser breaks the tool #14

Closed pwang2 closed 6 years ago

pwang2 commented 6 years ago

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

Tarpsvo commented 6 years ago

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. 👍

lanxin1234 commented 6 years ago

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/_prettier@1.13.0@prettier/index.js:7051:13) at formatWithCursor (/Users/lanc/Desktop/runbuild/node_modules/_prettier@1.13.0@prettier/index.js:10370:12) at /Users/lanc/Desktop/runbuild/node_modules/_prettier@1.13.0@prettier/index.js:31115:15 at Object.format (/Users/lanc/Desktop/runbuild/node_modules/_prettier@1.13.0@prettier/index.js:31134:12) at Object.module.exports (/Users/lanc/Desktop/runbuild/node_modules/_vue-loader@13.7.1@vue-loader/lib/template-compiler/index.js:80:23)

@ ./src/App.vue 11:0-392 @ ./src/main.js @ multi ./node_modules/_webpack-dev-server@2.11.2@webpack-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

lanxin1234 commented 6 years ago

How to solve this?

pwang2 commented 6 years ago

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
lovemyliwu commented 6 years ago

@pwang2 not work, still get 1.13.0 npm view prettier version

pwang2 commented 6 years ago

@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.

pwang2 commented 6 years ago

Merged.

Thanks @yyx990803 ! We could expect a new version of @vue/component-compiler-utils soon.

yyx990803 commented 6 years ago

Released in 1.3.1

yyx990803 commented 6 years ago

remove node_modules and reinstall everything.

liuhuidi commented 6 years ago

还是不行啊,尤大婶

pwang2 commented 6 years ago
rm -rf package-lock.json node_modules
npm install
lanxin1234 commented 6 years ago

rm -rf node_modules
npm install
npm install prettier@~1.12.1

liuhuidi commented 6 years ago

rm -rf node_modules npm install npm install prettier@~1.12.1 亲测有效,谢谢~

JesonRondo commented 6 years ago

nuxtjs still doesn't work.... The same error with prettier

lanxin1234 commented 6 years ago

you can try cd node_modules/ rm -rf _prettier@1.13.0@prettier cnpm install prettier@~1.12.1

(if your node_modules/ have _prettier@1.13.0@prettier )

transtone commented 6 years ago

@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了。

5amfung commented 6 years ago

Yarn and npm registries are still pointing to 1.13.0, not 1.13.1.

JesonRondo commented 6 years ago

@lanxin1234 it work with this manual install. @transtone only nuxt@1.4.0 has this error. It use vue-loader@13.7.0. But nuxt@1.4.0 is the newest stable version....

fyddaben commented 6 years ago

@lanxin1234 是的,需要删掉,我是这样写的,成功了,感谢

rm -rf node_modules
cnpm cache verify
cnpm i
rm -rf node_modules/_prettier@1.13.0@prettier
cnpm install --save-dev prettier@1.12.0
momolizi commented 6 years ago

上面的方法都试了,还是报错

outstandinglife commented 6 years ago

rm -rf node_modules npm install npm install prettier@~1.12.1 我的成功了

superfff commented 6 years ago

楼上我也是不行~

今天打算把线上的分支拉多一个到本地做迭代. 然后装完package就报错了. 旧的包是可以的.

我还以为是跟同事更新代码搞错了 - -

qidaizhe11 commented 6 years ago

分享下,此官方修复只针对 vue-loader 15.x 版本,如果你项目引用的是 13.x/14.x等版本,与此修复无关,需升级 vue-loader 至 15.x版,

升级后需要注意不兼容更新: https://vue-loader.vuejs.org/migrating.html#notable-breaking-changes

`// webpack.config.js const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = { // ... plugins: [ new VueLoaderPlugin() ] }`

outstandinglife commented 6 years ago

rm -rf node_modules npm install
rm -rf node_modules/_prettier@1.13.0@prettier npm install prettier@~1.12.1 试试这样

xiaofan9 commented 6 years ago

window 10 下

cnpm i
rm node_modules/_prettier@1.13.0@prettier
// 输入 a 回车
cnpm i prettier@~1.12.1 -D
tabqiang commented 6 years ago

删 node_modules npm install npm run dev 可以了

yangguang111lll commented 6 years ago

我也在报错

yangguang111lll commented 6 years ago

怎么做的?

jadepam commented 6 years ago

npm install --save-dev prettier@1.12.1

luanwulin commented 6 years ago

nuxt项目有大佬搞定了么,

nuxt@1.4.0
npm install --save-dev prettier@1.12.1

也不行

hejialianghe commented 6 years ago

npm install prettier@~1.12.1 这个是可以的

huyajie commented 6 years ago

@chengzhuotc 升级完vue -loader 后 没有其他的报错吗?有解决吗

liuhuidi commented 6 years ago

目前没有其他保错,已解决,谢谢😘

liuhuidi428 邮箱:liuhuidi428@163.com

签名由 网易邮箱大师 定制

在2018年05月28日 15:32,Ya jie 写道:

@chengzhuotc 升级完vue -loader 后 没有其他的报错吗?有解决吗

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

anqing-kingjay commented 6 years ago

为什么我npm install --save-dev prettier@1.12.1也会报错

chengzhuotc commented 6 years ago

@huyajie image这样做就好了

yangguang111lll commented 6 years ago

default 还是不行

chengzhuotc commented 6 years ago

不知道是不是和node环境有关,我用的是10点几版本的,然后照着上面试了很多次不行,然后我吧vue-loader升级最新版本, image 在改下配置,然后照着上面降级就可以了

blairzhao111 commented 6 years ago

用的是 vue 2.3.0 和 vue -loader 14.2.1, 删了node_modules后重新npm install后还是报错;但手动install 1.12.1 版本的 prettier 就可以了

xuebingwang commented 6 years ago

作为一个node小白,这问题我也弄了一个多小时,最先还以为我哪里代码写错了,查了一通才查到这里,谷歌真牛掰,这个issue10几个小时前提的,谷歌就能搜出来了。

顺便鄙视一下百度

yangguang111lll commented 6 years ago

难道这问题作者没关注么?

tianxiaofeng747 commented 6 years ago

用 vue init 生成新项目,竟然报错, 好神奇啊。。。

yangguang111lll commented 6 years ago

感觉没权威性啊,老报错。。。

yangguang111lll commented 6 years ago

@tianxiaofeng 报错啊

tianxiaofeng747 commented 6 years ago

@yangguang111lll 我也报错, 老项目可以的。 奇怪。

luanwulin commented 6 years ago

nuxt项目解决了 在推送服务器上,装完依赖过后,手动单独安装一次prettier就好了 image

xiaofan9 commented 6 years ago

@yangguang111lll window 10 下

cnpm i rm node_modules/_prettier@1.13.0@prettier // 输入 a 回车 cnpm i prettier@~1.12.1 -D

jkf8x8 commented 6 years ago

试了4个小时,,试光了所有方法。。绝望

hlg-facai commented 6 years ago

心累

ChenArno commented 6 years ago

I can't me too

liuhuidi commented 6 years ago

🐣👏🏻👑给你,心累拿走!谢谢!

liuhuidi428 邮箱:liuhuidi428@163.com

签名由 网易邮箱大师 定制

在2018年05月28日 16:16,hlg-facai 写道:

心累

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.