Nuxt.js: Build error when run yarn dev after yarn build and yarn start

Created on 20 Jul 2020  Â·  7Comments  Â·  Source: nuxt/nuxt.js

Versions

  • nuxt: ^2.13.0
  • node: 12.8.2

Steps to reproduce

create nuxt app project and use the spa mode,

1.yarn build
2.yarn start
3.yarn dev

What is Expected?

Can work fine when switch both yarn build and yarn dev

What is actually happening?

image

Note: yarn dev ==> yarn build is fine, but yarn build ==> yarn dev, will build error
After the build error happen, I need to remove the node_mould folder, especially need to yarn cache clean thenyarn install again, after that, yarn dev work back.

pending-info question

Most helpful comment

OK, reproduced. It happens because you do build with nuxt-ts and than run dev with nuxt ( without ts). config is cached when its build with nuxt-ts and when u run it without ts it result in syntax error. Use either nuxt for everything or nuxt-ts

All 7 comments

Hi @Quineone. I think you are using nuxt with programmatic usage with manual importing of nuxt config. In that case, you need to use esm. Sharing a reproduction or at least package.json (scripts) would be appreciated.

Hi @pi0, have the same issue. Here's the repo
https://github.com/MontolioV/test-nuxt-dev-build-bug
It's just a clean setup with create-nuxt-app:

create-nuxt-app v3.1.0
✨  Generating Nuxt.js project in test-nuxt-dev-build-bug
? Project name: test-nuxt-dev-build-bug
? Programming language: TypeScript
? Package manager: Npm
? UI framework: None
? Nuxt.js modules: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Linting tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Testing framework: None
? Rendering mode: Universal (SSR / SSG)
? Deployment target: Server (Node.js hosting)
? Development tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)

Problem is the same.

Steps to reproduce:

  1. npm run build
  2. npm run dev <---- fails with SyntaxError: Unexpected token 'export'
  3. modify nuxt.config.js (I just add an empty line at the end of file)
  4. npm run dev <---- works correctly

https://codesandbox.io/s/github/MontolioV/test-nuxt-dev-build-bug - works fine, no syntax error
What you describe doesn't make any sense as it seems like a something weird with your files/node

@aldarund hi! Possibly. I decided to describe it, as I saw the issue with the similar problem.
Just checked on other machine: Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-1065-aws x86_64), node -v 13.12.0, cloned https://github.com/MontolioV/test-nuxt-dev-build-bug. The same behavior as I described.
Also checked Windows 10 Version 10.0.18363 Build 18363, node -v 14.6.0 and 12.18.2 - same behavior.

Untitled

OK, reproduced. It happens because you do build with nuxt-ts and than run dev with nuxt ( without ts). config is cached when its build with nuxt-ts and when u run it without ts it result in syntax error. Use either nuxt for everything or nuxt-ts

hi @aaronransley , thank you very much, it work. So will you update this to cli on further version?

It is actually fixed in CNA already, just not released https://github.com/nuxt/create-nuxt-app/pull/568
closing this. To fix this issue manually just change dev command from nuxt to nuxt-ts

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredreich picture jaredreich  Â·  3Comments

maicong picture maicong  Â·  3Comments

shyamchandranmec picture shyamchandranmec  Â·  3Comments

vadimsg picture vadimsg  Â·  3Comments

mattdharmon picture mattdharmon  Â·  3Comments