nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 246 forks source link

"export 'default' (imported as 'defu') was not found in 'defu' #506

Closed rodrigopv closed 3 years ago

rodrigopv commented 3 years ago

(as the other issue closed, maybe this one is a different case)

Sorry for the delay in testing the new version. It seems that new release 5.13.5 makes nuxt render the page properly, but now when visiting the page after npm run dev, the following error appears on chrome console:

image

Please note that:

    "@nuxtjs/axios": {
      "version": "5.13.5",
      "resolved": "https://registry.npmjs.org/@nuxtjs/axios/-/axios-5.13.5.tgz",
      "integrity": "sha512-GyeuiseDCwfRGDQH/gK+lngCseZS3SQm3q6xqiVx5xQnzCqokojN3uJkNB0DdHCowBP1aim+mDhu3spzcCnyBg==",
      "requires": {
        "@nuxtjs/proxy": "^2.1.0",
        "axios": "^0.21.1",
        "axios-retry": "^3.1.9",
        "consola": "^2.15.3",
        "defu": "^5.0.0"
      },

Also seen on Chrome console:

[HMR] bundle 'client' has 1 warnings
client.js?1b93:196 ./.nuxt/axios.js 73:31-35"export 'default' (imported as 'defu') was not found in 'defu'

This is happening on the same project that uses babel transpile for some reason (I think we should get rid of IE11 anyway).

pi0 commented 3 years ago

Hi. No worries and thanks for making new issue! Is it possible to help reproduce on sandbox? And do you also experience it with nuxt-edge? (2.16)

rodrigopv commented 3 years ago

It might be more difficult to reproduce this one, I already have a sandbox where I try to put as many libs as possible to recreate a big project like the one I'm working for here: https://codesandbox.io/s/loving-architecture-d9zuf?file=/nuxt.config.js

I'm still unable to trigger the error on this one, but I'll keep trying and in the meantime I'll try with nuxt-edge

cron13 commented 3 years ago

same problem fixed by downgrading defu to 4.0.1

rodrigopv commented 3 years ago

Hi @cron13,

Glad to find someone else to have this bug. Are you able to find the exact conditions that triggers it?

I've been trying to find on last days which configuration/packages trigger this but still no luck.

If you note, a vanilla nuxt install won't have any issue with latest nuxtjs/axios.

Please let me know if you can share your project or if you have a clue that I might work to reproduce.

cron13 commented 3 years ago

Hi, today is not a working day, so I just fixed the bug in a quick way to keep the site working I am using node v13.11.0 And here is my package.json

"dependencies": { "@babel/plugin-proposal-optional-chaining": "^7.8.3", "@nuxtjs/auth": "^4.8.4", "@nuxtjs/axios": "^5.9.5", "@nuxtjs/component-cache": "^1.1.5", "@nuxtjs/device": "^1.2.7", "@nuxtjs/pwa": "^3.0.0-beta.20", "@nuxtjs/router": "^1.5.0", "@nuxtjs/style-resources": "^1.0.0", "@popperjs/core": "^2.4.0", "@webcreate/infinite-ajax-scroll": "^3.0.0-beta.4", "apexcharts": "^3.16.0", "autosize": "^4.0.2", "color-hash": "^1.0.3", "cookie": "^0.4.0", "copy-to-clipboard": "^3.2.0", "core-js": "2", "cors": "^2.8.5", "dayjs": "^1.8.19", "dotenv": "^8.1.0", "fast-average-color": "^6.0.1", "filepond": "^4.12.2", "filepond-plugin-file-validate-type": "^1.2.4", "filepond-plugin-image-preview": "^4.5.0", "inputmask": "^5.0.3", "lg-video.js": "^1.0.0", "lightgallery.js": "^1.1.3", "locutus": "^2.0.11", "lodash": "^4.17.11", "micromodal": "0.4.2", "node-sass": "^4.13.1", "nuxt": "2.11.0", "nuxt-ssr-cache": "^1.5.1", "path-to-regexp": "^6.1.0", "portal-vue": "^2.1.7", "redis": "^3.0.2", "sass-loader": "^8.0.2", "scroll-lock": "^2.1.2", "survey-vue": "^1.5.15", "typograf": "^6.11.0", "vue-advanced-cropper": "^0.16.2", "vue-apexcharts": "^1.5.2", "vue-click-outside": "^1.0.7", "vue-color": "^2.7.0", "vue-cropperjs": "^4.0.1", "vue-filepond": "^6.0.2", "vue-inputmask": "^0.2.1", "vue-lazy-hydration": "^1.0.0-beta.12", "vue-pagination-2": "^2.0.3", "vue-picture-swipe": "^1.2.0", "vue-quill-editor": "^3.0.6", "vue-recaptcha": "^1.2.0", "vue-select": "^3.2.0", "vue-slide-up-down": "^2.0.1", "vue-slider-component": "^3.1.1", "vue-ya-metrica": "^1.0.2", "vue-yandex-maps": "^0.10.6", "vue2-datepicker": "^3.0.2", "vuedraggable": "^2.23.2", "vuex": "^3.1.2" }, "devDependencies": { "@babel/preset-env": "^7.12.17", "@nuxtjs/router-extras": "^1.1.0" }, "resolutions": { "@babel/preset-env": "7.12.17" }

rodrigopv commented 3 years ago

Hi,

I think i've found something important regarding this bug. It seems that switching npm for yarn would resolve the issue. That means that it must be related to dependency resolution.

I noticed that unlike the example sandbox from @pi0, the project that I'm working on doesn't include

    "defu": "^5.0.0",

on it's package.json

What doesn't work:

To reproduce:

  1. Have a working project with "@nuxtjs/axios": "5.13.1", (locked version)
  2. Modify it to "@nuxtjs/axios": "^5.13.1",
  3. run npm update "@nuxtjs/axios" so npm lockfile shows "version": "5.13.6",
  4. "export 'default' (imported as 'defu') was not found in 'defu'should appear now
  5. run npm install defu --save and expect the error to be gone

package-lock.json diff from the commented steps:

--- a/dashboard/package-lock.json
+++ b/dashboard/package-lock.json
@@ -2040,24 +2040,21 @@
       }
     },
     "@nuxtjs/axios": {
-      "version": "5.13.1",
-      "resolved": "https://registry.npmjs.org/@nuxtjs/axios/-/axios-5.13.1.tgz",
-      "integrity": "sha512-vZpXV2AAkQ5Duejubt1k3ZgUnYowYnPvmcUt0hskd+OebmQ+jF6Wk6rOG0/9EeknOxm7mtTGgKSwdlE1jDo+xA==",
+      "version": "5.13.6",
+      "resolved": "https://registry.npmjs.org/@nuxtjs/axios/-/axios-5.13.6.tgz",
+      "integrity": "sha512-XS+pOE0xsDODs1zAIbo95A0LKlilvJi8YW0NoXYuq3/jjxGgWDxizZ6Yx0AIIjZOoGsXJOPc0/BcnSEUQ2mFBA==",
       "requires": {
         "@nuxtjs/proxy": "^2.1.0",
         "axios": "^0.21.1",
         "axios-retry": "^3.1.9",
         "consola": "^2.15.3",
-        "defu": "^3.2.2"
+        "defu": "^5.0.0"
       },
       "dependencies": {
-        "axios": {
-          "version": "0.21.1",
-          "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
-          "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
-          "requires": {
-            "follow-redirects": "^1.10.0"
-          }
+        "defu": {
+          "version": "5.0.0",
+          "resolved": "https://registry.npmjs.org/defu/-/defu-5.0.0.tgz",
+          "integrity": "sha512-VHg73EDeRXlu7oYWRmmrNp/nl7QkdXUxkQQKig0Zk8daNmm84AbGoC8Be6/VVLJEKxn12hR0UBmz8O+xQiAPKQ=="
         }
       }
     },
@@ -5207,9 +5204,9 @@
       }
     },
     "defu": {
-      "version": "3.2.2",
-      "resolved": "https://registry.npmjs.org/defu/-/defu-3.2.2.tgz",
-      "integrity": "sha512-8UWj5lNv7HD+kB0e9w77Z7TdQlbUYDVWqITLHNqFIn6khrNHv5WQo38Dcm1f6HeNyZf0U7UbPf6WeZDSdCzGDQ=="
+      "version": "5.0.0",
+      "resolved": "https://registry.npmjs.org/defu/-/defu-5.0.0.tgz",
+      "integrity": "sha512-VHg73EDeRXlu7oYWRmmrNp/nl7QkdXUxkQQKig0Zk8daNmm84AbGoC8Be6/VVLJEKxn12hR0UBmz8O+xQiAPKQ=="
     },
     "degenerator": {
       "version": "2.2.0",
@@ -12723,6 +12720,13 @@
       "integrity": "sha512-DC7t66WeIrlVzVMzickfHIn1zHu7eMsVNiH0nkD/wCrijFQdvgyfH2zc5lkFf79EApUgRhZntkpKjfgLkn2i/Q==",
       "requires": {
         "defu": "^3.2.2"
+      },
+      "dependencies": {
+        "defu": {
+          "version": "3.2.2",
+          "resolved": "https://registry.npmjs.org/defu/-/defu-3.2.2.tgz",
+          "integrity": "sha512-8UWj5lNv7HD+kB0e9w77Z7TdQlbUYDVWqITLHNqFIn6khrNHv5WQo38Dcm1f6HeNyZf0U7UbPf6WeZDSdCzGDQ=="
+        }
       }
     },
     "serve-static": {
rodrigopv commented 3 years ago

Also, here it's the diff on package-lock.json before adding defu as a direct dependency:

@@ -2040,24 +2040,21 @@
       }
     },
     "@nuxtjs/axios": {
-      "version": "5.13.1",
-      "resolved": "https://registry.npmjs.org/@nuxtjs/axios/-/axios-5.13.1.tgz",
-      "integrity": "sha512-vZpXV2AAkQ5Duejubt1k3ZgUnYowYnPvmcUt0hskd+OebmQ+jF6Wk6rOG0/9EeknOxm7mtTGgKSwdlE1jDo+xA==",
+      "version": "5.13.6",
+      "resolved": "https://registry.npmjs.org/@nuxtjs/axios/-/axios-5.13.6.tgz",
+      "integrity": "sha512-XS+pOE0xsDODs1zAIbo95A0LKlilvJi8YW0NoXYuq3/jjxGgWDxizZ6Yx0AIIjZOoGsXJOPc0/BcnSEUQ2mFBA==",
       "requires": {
         "@nuxtjs/proxy": "^2.1.0",
         "axios": "^0.21.1",
         "axios-retry": "^3.1.9",
         "consola": "^2.15.3",
-        "defu": "^3.2.2"
+        "defu": "^5.0.0"
       },
       "dependencies": {
-        "axios": {
-          "version": "0.21.1",
-          "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
-          "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
-          "requires": {
-            "follow-redirects": "^1.10.0"
-          }
+        "defu": {
+          "version": "5.0.0",
+          "resolved": "https://registry.npmjs.org/defu/-/defu-5.0.0.tgz",
+          "integrity": "sha512-VHg73EDeRXlu7oYWRmmrNp/nl7QkdXUxkQQKig0Zk8daNmm84AbGoC8Be6/VVLJEKxn12hR0UBmz8O+xQiAPKQ=="
         }
       }
     },
chivalrus commented 3 years ago

It seems reinstalling axios using yarn works for me.

yarn add @nuxtjs/axios

mukundshah commented 3 years ago

I just used yarn add defu and the error is gone

Yarn: 1.22.15 Node: 14.18.1 (nvm)

pi0 commented 3 years ago

Please mention if still having issues with latest versions and fresh lockfile with npx nuxi info

Sonit90 commented 2 years ago

I cannot fix the issue with pnpm, npm, yarn.

To reproduce - clone this: https://github.com/antfu/vitesse-nuxt-bridge

Uncaught SyntaxError: The requested module '/_nuxt/node_modules/defu/dist/defu.cjs?import' does not provide an export named 'defu' (at composables.mjs:3:10)