40

I was just setting up a vue project using the webpack template like stated here: http://vuejs-templates.github.io/webpack/

However after running npm run dev just to test that the template is working, I get this error:

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)

What am I doing wrong?

3
  • It looks like I beat you to the question by one minute: stackoverflow.com/questions/50555943/… May 27, 2018 at 19:59
  • Looks like there's an error in vue-cli, downgrade probably
    – Ohgodwhy
    May 27, 2018 at 20:10
  • I'm getting this issue with vue and webpack; there's no vue-cli in use in my project at all. It isn't even installed. May 27, 2018 at 20:33

7 Answers 7

83

Prettier has caused this regression in their 1.13.0 update which occurred today. Downgrade to the previous version to fix this error:

npm install --save-dev [email protected]

npm run dev

That should do the trick.

3
  • 1
    Worked great for me using npm. Thanks!
    – Alex
    May 28, 2018 at 7:57
  • Now removing node_modules and package-lock.json and npm install will fix it.
    – Arolia
    May 28, 2018 at 8:03
  • 2
    This works for me! Wow, one bad update to 1 package and the whole project breaks. That's the current state of the javascript landscape May 28, 2018 at 11:45
8

it is fixed in [email protected] and [email protected]. So just upgrade.

7

If you're using Yarn add this to your package.json to force @vue/component-compiler-utils to use the right version:

"resolutions": {
  "@vue/component-compiler-utils/prettier": "1.12.1"
}

Then do a fresh install.

reference

1
  • But change the version of prettier to 1.12.0 works for me.
    – soarinblue
    May 29, 2018 at 1:27
2

If you are using laravel-mix then this fixed it for me:

Remove .\node_modules, remove .\yarn.lock then add following to .\package.json

"dependencies": {
    ...
    "prettier": "1.12.1",
    "vue-loader": "13.7.0"
    ...
},
"resolutions": {
    "laravel-mix/vue-loader": "13.7.0",
    "vue-loader/prettier": "1.12.1"
}

run yarn and all should be working.

1

Since vue-cli uses prettier API interface here and hardcoded the options, and prettier dependency was added in project @vue/component-compiler-utils.

You could try npm i prettier@~1.12.0 to force the prettier version here.

BTW someone did a pull request with the fix

0
0

I got the same error with yarn, but tried npm i and npm run dev instead and it worked.

yarn v v1.5.1 npm -v 5.6.0 node -v v10.0.0

0

I use Nuxt/Vue on Docker. I got same error with docker build.

It doesn't work after below commands

rm -rf node_modules 
npm install --save-dev [email protected]
npm run dev

So I edited Dockerfile like this and it worked.

FROM node:8.11

RUN mkdir -p /app
COPY . /app
WORKDIR /app

RUN npm install && npm cache verify
RUN npm install --save-dev [email protected]
RUN npm run build

EXPOSE 3000

CMD ["npm", "run", "express"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.