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

 @ ./layouts/error.vue 7:0-368
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi webpack-hot-middleware/client?name=client&reload=true&timeout=30000&path=/__webpack_hmr ./.nuxt/client.js

I'm having same issue on Nuxtjs. Anyone facing same issue??? Help?!! version: "nuxt": "^1.0.0", "prettier": "^1.12.1"

Tried all the option of downgrading and upgrading prettier version.

Hardik Shah
  • 1,366
  • 2
  • 15
  • 35

3 Answers3

30

Downgrade prettier package to version 1.12.1 and stick with it:

npm i prettier@1.12.1 --save-dev --save-exact

vvt
  • 301
  • 2
  • 3
27

UPDATE: I mentioned this in the comment below but for some reason people still refer to the same thing.

Please note that this is a hack... A temporary one at that. But it's meant for people who want to get their work done right now... While waiting for a permanent fix to ship. As you might have guessed... A PR has already been submitted and already been merged. Which means a fix is coming within the next release. In the meantime... This will do. And yes when that release comes in it will override this hack and none of this would seem to have happened. Cheers

Dont even bother to downgrade. Its a minor issue. I gave an explanation and what worked for me here: In a nutshell: Go to: node_modules\vue-loader\lib\template-compiler ...open index.js and look for

// prettify render fn if (!isProduction) { code = prettier.format(code, { semi: false}) }

and change the lines to:

// prettify render fn
if (!isProduction) {
  code = prettier.format(code, { semi: false, parser: 'babylon' })
}

Thats it!

Wale
  • 1,321
  • 16
  • 11
  • but this is a temporary fix, surely downgrading is safer? – nxmohamad May 29 '18 at 15:57
  • 2
    This is just a hack instead of a fix. – Gerald May 30 '18 at 02:18
  • 1
    As I already mentioned downgrading and upgrading of prettier version not working in Nuxtjs. So this as a temporary fix working. – Hardik Shah May 30 '18 at 05:37
  • Yes Gerald and Hardik. This is a hack... A temporary one at that. But it's meant for people who want to get their work done right now... While waiting for a permanent fix to ship. As you might have guessed... A PR has already been submitted and already been merged. Which means a fix is coming within the next release. In the meantime... This will do. And yes when that release comes in it will override this hack and none of this would seem to have happened. Cheers. – Wale May 30 '18 at 06:19
  • 1
    This is a hack, and not a long-term viable solution. – Oldenborg May 30 '18 at 08:20
  • great, very helpfull – Darlan Dieterich Oct 10 '18 at 11:16
  • 1
    Now use `parser: 'babel'` instead – lacostenycoder Apr 29 '19 at 19:36
-1

Here's a sed one-liner that fixes it for now:

sed -i 's/semi: false/semi: false, parser: \"babylon\"/g' node_modules/vue-loader/lib/template-compiler/index.js

And for mac:

sed -i '' 's/semi: false/semi: false, parser: \"babylon\"/g' node_modules/vue-loader/lib/template-compiler/index.js

And as an npm script:

"scripts": {
  "postinstall": "sed -i 's/semi: false/semi: false, parser: \"babylon\"/g' node_modules/vue-loader/lib/template-compiler/index.js"
}
Aronanda
  • 191
  • 1
  • 2
  • 3