nuxt: [2.4.0] [npm] Unexpected token error when running in dev

Version

v2.4.0

Reproduction link

https://i-cannot-share-private-repos.com/

Steps to reproduce

  1. Upgrade a codebase to Nuxt 2.4.0.
  2. Run nuxt to build for dev.

What is expected ?

It compiles and builds the web site.

What is actually happening?

It throws an error:

ERROR  in ./.nuxt/router.js                                                                         friendly-errors 12:33:55

Module parse failed: Unexpected token (9:24)                                                         friendly-errors 12:33:55
You may need an appropriate loader to handle this file type.
| 
| var _c67eeace = function _c67eeace() {
>   return interopDefault(import('../pages/about-us.vue'
|   /* webpackChunkName: "pages/about-us" */
|   ));
                                                                                                     friendly-errors 12:33:55
 @ ./.nuxt/index.js 8:0-43 64:19-31
 @ ./.nuxt/client.js
 @ multi eventsource-polyfill webpack-hot-middleware/client?reload=true&timeout=30000&ansiColors=&overlayStyles=&name=client&path=/__webpack_hmr/client ./.nuxt/client.js

Additional comments?

All I did was upgrade using npm install -D nuxt@2.4.0 to get the latest version. Not sure if there are other changes I need to make (nothing was mentioned in the release notes).

<div align="right">This bug report is available on Nuxt community (#c8553)</div>

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 16 (10 by maintainers)

Most upvoted comments

“ npm should either remove package-lock.json and reinstall before upgrade or use npm update acorn --depth 20 && npm dedupe after upgrading to 2.4.0.“ i remove node_modules, then remove package-lock.json, then update nuxt and reinstall, it’s work. only remove package-lock.json and reinstall it’s not useful to me. hope to help you.

PS: Alternative official module is style-resources-module

Upgrading to nuxt@2.4.0 and removing package-lock.json seems to have fixed the issue. But it seems that a module I use nuxt-sass-resources-loader is not working anymore. Don’t know if it’s related to 2.4.0.

Do we have to use a module like this now?

module.exports = {
  modules: [
    "@nuxtjs/axios",
    "@nuxtjs/dotenv",
    "@nuxtjs/pwa",
    "nuxt-material-design-icons",
    [
      "nuxt-sass-resources-loader",
      [
        // Global variables, site-wide settings, config switches, etc
        "@/assets/settings/_settings.colors.scss",

        // Site-wide mixins and functions
        "@/assets/tools/_tools.mq.scss"
      ]
  ]
}

This is probably related to webpack regression. Please remove yarn.lock / package-lock.json and reinstall. This should fix the problem. (Originally discovered by @manniL few days ago)

Link to the issue: https://github.com/webpack/webpack/issues/8656

Update

Alternative solution:

npm update acorn --depth 20
npm dedupe

Related issue: #4839

I also have the same issue. I am using nuxt@2.3.4. I just removed package.lock and reinstalled packages but the error still persists.