简体   繁体   中英

require() of ES Module when using @nuxtjs/composition-api

I have the following error in my nuxt-2 + storyblok project, when I switched from @vue/composition-api to @nuxtjs/composition-api :

require() of ES Module /Users/my-user/Sites/my-project/node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs not supported. Instead change the require of /Users/my-user/Sites/my-project/node_modules/@nuxtjs/composition-api/dist/runtime/index.mjs to a dynamic import() which is available in all CommonJS modules.

my console log also throws: Uncaught InternalError: too much recursion

I already use "type":"module" in my package.json. -> It makes no difference whether I remove it or not.

Some version info from my package.json:

  • "nuxt": "^2.15.8",
  • "@nuxtjs/composition-api": "^0.33.1",
  • "@storyblok/nuxt-2": "^1.1.0",
  • "core-js": "^3.19.3",

I included the composition-api like this

modules: [
  '@nuxtjs/composition-api/module',
  ...
],

On Stackoverflow there are others who have this issue with node-fetch , but I don't have this dependency installed.

I could update from @nuxtjs/composition-api to Nuxt Bridge , but it's a lot of changes and I am not sure it helps, or my code even works with Bridge.

Hi have you tried to move it to "buildModules" and remove the "/module" in the url? It should be:

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    '@nuxtjs/composition-api',
    ...
  ],

Downgrading to @nuxtjs/composition-api version 0.29.3 solved the issue. Version 0.30.0 starts to use mjs which seems to not be compatible with the current version of @storyblok/nuxt-2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM