Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt / Webpack / Vue CLI build fails with v6.2.0 and above #718

Closed
itpropro opened this issue Sep 6, 2021 · 21 comments
Closed

Nuxt / Webpack / Vue CLI build fails with v6.2.0 and above #718

itpropro opened this issue Sep 6, 2021 · 21 comments

Comments

@itpropro
Copy link
Contributor

itpropro commented Sep 6, 2021

Since 6.2.0, Nuxt fails to build (I think because of the changed file extensions):

[fatal] Nuxt build error
  ERROR in ./node_modules/@vueuse/core/index.mjs 800:50-62
  Can't import the named export 'bypassFilter' from non EcmaScript module (only default export is available)
  @ ./layouts/default.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--2-0!./node_modules/babel-loader/lib??ref--2-1!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./layouts/default.vue?vue&type=script&lang=js&)
  @ ./layouts/default.vue?vue&type=script&lang=js&
  @ ./layouts/default.vue
  @ ./node_modules/.cache/nuxt/App.js
  @ ./node_modules/.cache/nuxt/index.js
  @ ./node_modules/.cache/nuxt/client.js
  @ multi ./node_modules/@nuxt/components/lib/installComponents.js ./node_modules/.cache/nuxt/composition-api/register.js ./node_modules/.cache/nuxt/client.js
  
  ERROR in ./node_modules/@vueuse/core/index.mjs 3271:25-30
  Can't import the named export 'clamp' from non EcmaScript module (only default export is available)
  @ ./layouts/default.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--2-0!./node_modules/babel-loader/lib??ref--2-1!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./layouts/default.vue?vue&type=script&lang=js&)
  @ ./layouts/default.vue?vue&type=script&lang=js&
  @ ./layouts/default.vue
  @ ./node_modules/.cache/nuxt/App.js
  @ ./node_modules/.cache/nuxt/index.js
  @ ./node_modules/.cache/nuxt/client.js
  @ multi ./node_modules/@nuxt/components/lib/installComponents.js ./node_modules/.cache/nuxt/composition-api/register.js ./node_modules/.cache/nuxt/client.js

4500+ lines ...
@antfu
Copy link
Member

antfu commented Sep 6, 2021

That's weird, can you remove the ./node_modules/.cache and try again?

@antfu
Copy link
Member

antfu commented Sep 6, 2021

I found this can confirmed it fixes the same issue on Vue CLI

https://stackoverflow.com/a/64907659

Nuxt
// nuxt.config.js

module.exports = {
  build: {
    extend (config) {
      config.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      })
    }
  }
}
Vue CLI
// vue.config.js

module.exports = {
  configureWebpack: {
    module: {
      rules: [{
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      }]
    }
  }
}

/cc @pi0 @danielroe @sodatea I am not super familiar what is going on internally in webpack, but if this fix makes sense, should we include it by default in Nuxt / Vue CLI?

@danielroe
Copy link
Contributor

danielroe commented Sep 6, 2021

Likely this should be included by default for wp4 in Vue CLI. It should already be present in next version of Nuxt (2.16): nuxt/nuxt#9180

And it is already injected by @nuxtjs/composition-api when that is being used

@antfu
Copy link
Member

antfu commented Sep 6, 2021

Closing this as this is not an issue of the project itself and an workaround is provided.

@antfu antfu closed this as completed Sep 6, 2021
@itpropro
Copy link
Contributor Author

itpropro commented Sep 6, 2021

Thanks for the provided workaround!

I've added it to my nuxt.config.json, but the problem still persists:

export default {
  // Fix to load .mjs modules correctly, see https://github.com/vueuse/vueuse/issues/718
  extend(config) {
    config.module.rules.push({
      test: /\.mjs$/,
      include: /node_modules/,
      type: 'javascript/auto',
    })
  },
...

Using nuxt 2.15.8 and @nuxtjs/composition-api 0.28.0. Would the workaround be to wait for Nuxt 2.16 to be released and hold back the update until then @danielroe?

@antfu
Copy link
Member

antfu commented Sep 6, 2021

Can you share a minimal reproduction? Thanks.

@antfu antfu changed the title Nuxt build fails with .mjs/.cjs extensions Nuxt / Webpack / Vue CLI build fails with v6.2.0 and above Sep 7, 2021
@antfu antfu pinned this issue Sep 7, 2021
@daopk
Copy link

daopk commented Sep 7, 2021

Nuxt

The extend method is an option of the build property, so the correct configuration should be

// nuxt.config.js

export default {
  build: {
    extend(config) {
      config.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      });
    }
  }
}

@patrikengborg
Copy link

patrikengborg commented Sep 8, 2021

Tried the proposed solution above from @daofresh, but now the error is this:

Module not found: Error: Can't resolve '@vue/composition-api/dist/vue-composition-api.esm.js' in '/Users/myuser/Code/myproject/node_modules/vue-demi/lib'

@danielroe
Copy link
Contributor

danielroe commented Sep 8, 2021

@patrikengborg Would you check whether there is a problem when you upgrade to the latest version of node 12 or 14 (and also ensure you are using the latest version of vue composition API).

@patrikengborg
Copy link

@danielroe I'm on node 14.17.5 and upgrading the composition api to latest seems to have solved it, thanks!
However, I get another error now vueDemi.getCurrentScope is not a function, when using the onClickOutside function, but I haven't investigated, so that might be on me.

@itpropro
Copy link
Contributor Author

itpropro commented Sep 8, 2021

Nuxt

The extend method is an option of the build property, so the correct configuration should be

// nuxt.config.js

export default {
  build: {
    extend(config) {
      config.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      });
    }
  }
}

Thanks for your reply, I had it in my build config, but failed to copy the config correctly into this issue ;)

@itpropro
Copy link
Contributor Author

itpropro commented Sep 8, 2021

@danielroe I'm on node 14.17.5 and upgrading the composition api to latest seems to have solved it, thanks!
However, I get another error now vueDemi.getCurrentScope is not a function, when using the onClickOutside function, but I haven't investigated, so that might be on me.

I had that problem with Nuxt, but fixed it by updating @vue/composition-api, that implemented these since v1.1

@itpropro
Copy link
Contributor Author

itpropro commented Sep 8, 2021

Can you share a minimal reproduction? Thanks.

I cannot reproduce it with a new nuxt repo, so it has to be somewhere in my configuration or modules. I will have to fix that myself :)

@michealroberts
Copy link
Contributor

Nuxt

The extend method is an option of the build property, so the correct configuration should be

// nuxt.config.js

export default {
  build: {
    extend(config) {
      config.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      });
    }
  }
}

I can confirm that this also worked for me, Nuxt 2.15.7 and @nuxtjs/composition-api": "^0.27.0 (@vueuse/core v6.2.1)

@SachinAgarwal1337
Copy link

SachinAgarwal1337 commented Sep 12, 2021

@antfu I am using this library wih ionic 5 with vue and I am not able to resolve it this with given suggesions.
Any idea how can it be resolved for ionic?

@sxzz
Copy link
Member

sxzz commented Sep 14, 2021

@antfu Hello, element-plus uses this library. Is there a way for users to use it with zero configuration? Thanks.

@antfu
Copy link
Member

antfu commented Sep 14, 2021

The way I see it is that Webpack 4 should release a patch to have built-in support for .mjs files (Note that Webpack 5, Vite, Rollup are working fine with this). Giving the whole ecosystem is moving in that direction, it's not a problem that is only limited to this library.

For some context:

@benoitlahoz
Copy link

I've been trying to get rid of this error using the configuration proposed by @antfu in a Storybook + Vue + Typescript project.
Error doesn't show anymore, but Storybook Webpack server doesn't work anymore ("Cannot GET /").
Any idea for Storybook support?

@trry-hub
Copy link

I found this can confirmed it fixes the same issue on Vue CLI

https://stackoverflow.com/a/64907659

Nuxt
// nuxt.config.js

module.exports = {
  build: {
    extend (config) {
      config.module.rules.push({
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      })
    }
  }
}
Vue CLI
// vue.config.js

module.exports = {
  configureWebpack: {
    module: {
      rules: [{
        test: /\.mjs$/,
        include: /node_modules/,
        type: "javascript/auto"
      }]
    }
  }
}

/cc @pi0 @danielroe @sodatea I am not super familiar what is going on internally in webpack, but if this fix makes sense, should we include it by default in Nuxt / Vue CLI?

@antfu
我使用的是cli 这样配置本地可以正常运行,但在打包时,element-plus并没有被打包进项目

I used cli so that the configuration would work properly locally, but element-plus was not packaged into the project when it was packaged.

@sxzz
Copy link
Member

sxzz commented Oct 25, 2021

@Bliangjs The problem you described has NOTHING to do with VueUse, please report issue to element-plus project.

@sxzz
Copy link
Member

sxzz commented Oct 28, 2021

If you're using Vue CLI 4, please upgrade to latest version. https://github.com/vuejs/vue-cli/releases/tag/v4.5.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants