unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.85k stars 493 forks source link

`LRUCache` dependency conflict for named exports #1177

Open issue-up[bot] opened 1 year ago

issue-up[bot] commented 1 year ago
   Forwarded from downstream issue: - https://github.com/nuxt/nuxt/issues/20368 by @tenfei4

### Environment Node.js v18.6.0 Nuxt v3.4.1 ### Reproduction file:///D:/node/nuxt_app/.output/server/chunks/node-server.mjs:7557 const parserCache$2 = new LRU({ ^ TypeError: LRU is not a constructor at file:///D:/node/nuxt_app/.output/server/chunks/node-server.mjs:7557:23 at ModuleJob.run (node:internal/modules/esm/module_job:193:25) at async Promise.all (index 0) at async ESMLoader.import (node:internal/modules/esm/loader:541:24) at async loadESM (node:internal/process/esm_loader:83:5) at async handleMainPromise (node:internal/modules/run_main:65:12) Node.js v18.6.0 ### Describe the bug when upgrade nuxt from v3.2 to v3.4.1 white nuxt upgrade --force. in dev mod.all ok. when build,found this error. ### Additional context _No response_ ### Logs _No response_
pi0 commented 1 year ago

Some context about dependency versions:

The new named export LRUCache is from lru-cache v9 and unstorage now uses it (https://github.com/unjs/unstorage/commit/5b8fc629dc23609f8de1a9d9f009835505180acb)

Some dependency in the tree is using an older (and hoisted!) version of lru-cache that makes this problem. It is impossible without reproduction to tell what is the issue but ideally finding that dependency using npm why lru-cache / pnpm why lru-cache can be proper fix.

nuxt reproduction: https://github.com/nuxt/nuxt/issues/20368#issuecomment-1514874444

tenfei4 commented 1 year ago

The problem still exists after using npm why lru-cache, and has tried to upgrade to nuxt v3.4.2 with the same problem.

pi0 commented 1 year ago

@tenfei4 Would you mind sharing the npm-why check result? (or your package.json could be also useful)

tenfei4 commented 1 year ago

package.json

{
  "private": true,
  "scripts": {
    "dev": "nuxt dev",
    "build": "nuxt build",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "@nuxtjs/tailwindcss": "^6.1.3",
    "nuxt": "^3.4.2",
    "nuxt-icons": "^3.1.0",
    "nuxt-lazyimages": "^0.2.0"
  },
  "dependencies": {
    "@ckeditor/ckeditor5-build-balloon": "^35.4.0",
    "@ckeditor/ckeditor5-vue": "^4.0.1",
    "axios": "^1.1.3",
    "cropperjs": "^1.5.12",
    "gsap": "^3.11.5",
    "html2canvas": "^1.4.1",
    "mysql2": "^3.2.3",
    "nodemailer": "^6.8.0",
    "qrcode.vue": "^3.3.3",
    "redis": "^4.4.0",
    "sharp": "^0.31.3",
    "vue-img-viewr": "^2.0.11",
    "vue3-toastify": "^0.0.3"
  }
}

npm why lru-cache

lru-cache@8.0.5
node_modules/lru-cache
  lru-cache@"^8.0.0" from mysql2@3.2.3
  node_modules/mysql2
    mysql2@"^3.2.3" from the root project

lru-cache@7.18.3
node_modules/named-placeholders/node_modules/lru-cache
  lru-cache@"^7.14.1" from named-placeholders@1.1.3
  node_modules/named-placeholders
    named-placeholders@"^1.1.3" from mysql2@3.2.3
    node_modules/mysql2
      mysql2@"^3.2.3" from the root project

lru-cache@6.0.0
node_modules/semver/node_modules/lru-cache
  lru-cache@"^6.0.0" from semver@7.5.0
  node_modules/semver
    semver@"^7.3.5" from css-loader@5.2.7
    node_modules/css-loader
      css-loader@"^5.0.0" from @nuxt/postcss8@1.1.3
      node_modules/@nuxt/postcss8
        @nuxt/postcss8@"^1.1.3" from @nuxtjs/tailwindcss@6.6.6
        node_modules/@nuxtjs/tailwindcss
          dev @nuxtjs/tailwindcss@"^6.1.3" from the root project
    semver@"^7.3.5" from node-abi@3.40.0
    node_modules/node-abi
      node-abi@"^3.3.0" from prebuild-install@7.1.1
      node_modules/prebuild-install
        prebuild-install@"^7.1.1" from sharp@0.31.3
        node_modules/sharp
          sharp@"^0.31.3" from the root project
    semver@"^7.4.0" from nitropack@2.3.3
    node_modules/nitropack
      nitropack@"^2.3.3" from nuxt@3.4.2
      node_modules/nuxt
        dev nuxt@"^3.4.2" from the root project
    semver@"^7.3.4" from postcss-loader@4.3.0
    node_modules/postcss-loader
      postcss-loader@"^4.1.0" from @nuxt/postcss8@1.1.3
      node_modules/@nuxt/postcss8
        @nuxt/postcss8@"^1.1.3" from @nuxtjs/tailwindcss@6.6.6
        node_modules/@nuxtjs/tailwindcss
          dev @nuxtjs/tailwindcss@"^6.1.3" from the root project
    semver@"^7.3.8" from sharp@0.31.3
    node_modules/sharp
      sharp@"^0.31.3" from the root project
    semver@"^7.3.4" from vscode-languageclient@7.0.0
    node_modules/vscode-languageclient
      vscode-languageclient@"^7.0.0" from vite-plugin-checker@0.5.6
      node_modules/vite-plugin-checker
        vite-plugin-checker@"^0.5.6" from @nuxt/vite-builder@3.4.2
        node_modules/@nuxt/vite-builder
          @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
          node_modules/nuxt
            dev nuxt@"^3.4.2" from the root project
    semver@"^7.3.5" from @mapbox/node-pre-gyp@1.0.10
    node_modules/@mapbox/node-pre-gyp
      @mapbox/node-pre-gyp@"^1.0.5" from @vercel/nft@0.22.6
      node_modules/@vercel/nft
        @vercel/nft@"^0.22.6" from nitropack@2.3.3
        node_modules/nitropack
          nitropack@"^2.3.3" from nuxt@3.4.2
          node_modules/nuxt
            dev nuxt@"^3.4.2" from the root project
    semver@"^7.5.0" from @nuxt/kit@3.4.2
    node_modules/@nuxt/kit
      @nuxt/kit@"3.4.2" from nuxt@3.4.2
      node_modules/nuxt
        dev nuxt@"^3.4.2" from the root project
      @nuxt/kit@"^3.0.0" from nuxt-icons@3.1.0
      node_modules/nuxt-icons
        dev nuxt-icons@"^3.1.0" from the root project
      @nuxt/kit@"^3.0.0" from nuxt-lazyimages@0.2.0
      node_modules/nuxt-lazyimages
        dev nuxt-lazyimages@"^0.2.0" from the root project
      @nuxt/kit@"^3.3.3" from @nuxt/telemetry@2.2.0
      node_modules/@nuxt/telemetry
        @nuxt/telemetry@"^2.2.0" from nuxt@3.4.2
        node_modules/nuxt
          dev nuxt@"^3.4.2" from the root project
      @nuxt/kit@"^3.3.1" from @nuxtjs/tailwindcss@6.6.6
      node_modules/@nuxtjs/tailwindcss
        dev @nuxtjs/tailwindcss@"^6.1.3" from the root project
      @nuxt/kit@"3.4.2" from @nuxt/vite-builder@3.4.2
      node_modules/@nuxt/vite-builder
        @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
        node_modules/nuxt
          dev nuxt@"^3.4.2" from the root project
    semver@"^7.3.4" from @nuxt/postcss8@1.1.3
    node_modules/@nuxt/postcss8
      @nuxt/postcss8@"^1.1.3" from @nuxtjs/tailwindcss@6.6.6
      node_modules/@nuxtjs/tailwindcss
        dev @nuxtjs/tailwindcss@"^6.1.3" from the root project

lru-cache@9.1.0 dev
node_modules/unstorage/node_modules/lru-cache
  lru-cache@"^9.0.3" from unstorage@1.5.0
  node_modules/unstorage
    unstorage@"^1.4.1" from nitropack@2.3.3
    node_modules/nitropack
      nitropack@"^2.3.3" from nuxt@3.4.2
      node_modules/nuxt
        dev nuxt@"^3.4.2" from the root project

lru-cache@5.1.1 dev
node_modules/@babel/helper-compilation-targets/node_modules/lru-cache
  lru-cache@"^5.1.1" from @babel/helper-compilation-targets@7.21.4
  node_modules/@babel/helper-compilation-targets
    @babel/helper-compilation-targets@"^7.21.4" from @babel/core@7.21.4
    node_modules/@babel/core
      @babel/core@"^7.21.3" from untyped@1.3.2
      node_modules/untyped
        untyped@"^1.3.2" from nuxt@3.4.2
        node_modules/nuxt
          dev nuxt@"^3.4.2" from the root project
        untyped@"^1.3.2" from @nuxt/kit@3.4.2
        node_modules/@nuxt/kit
          @nuxt/kit@"3.4.2" from nuxt@3.4.2
          node_modules/nuxt
            dev nuxt@"^3.4.2" from the root project
          @nuxt/kit@"^3.0.0" from nuxt-icons@3.1.0
          node_modules/nuxt-icons
            dev nuxt-icons@"^3.1.0" from the root project
          @nuxt/kit@"^3.0.0" from nuxt-lazyimages@0.2.0
          node_modules/nuxt-lazyimages
            dev nuxt-lazyimages@"^0.2.0" from the root project
          @nuxt/kit@"^3.3.3" from @nuxt/telemetry@2.2.0
          node_modules/@nuxt/telemetry
            @nuxt/telemetry@"^2.2.0" from nuxt@3.4.2
            node_modules/nuxt
              dev nuxt@"^3.4.2" from the root project
          @nuxt/kit@"^3.3.1" from @nuxtjs/tailwindcss@6.6.6
          node_modules/@nuxtjs/tailwindcss
            dev @nuxtjs/tailwindcss@"^6.1.3" from the root project
          @nuxt/kit@"3.4.2" from @nuxt/vite-builder@3.4.2
          node_modules/@nuxt/vite-builder
            @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
            node_modules/nuxt
              dev nuxt@"^3.4.2" from the root project
        untyped@"^1.3.2" from @nuxt/schema@3.4.2
        node_modules/@nuxt/schema
          @nuxt/schema@"3.4.2" from nuxt@3.4.2
          node_modules/nuxt
            dev nuxt@"^3.4.2" from the root project
          @nuxt/schema@"3.4.2" from @nuxt/kit@3.4.2
          node_modules/@nuxt/kit
            @nuxt/kit@"3.4.2" from nuxt@3.4.2
            node_modules/nuxt
              dev nuxt@"^3.4.2" from the root project
            @nuxt/kit@"^3.0.0" from nuxt-icons@3.1.0
            node_modules/nuxt-icons
              dev nuxt-icons@"^3.1.0" from the root project
            @nuxt/kit@"^3.0.0" from nuxt-lazyimages@0.2.0
            node_modules/nuxt-lazyimages
              dev nuxt-lazyimages@"^0.2.0" from the root project
            @nuxt/kit@"^3.3.3" from @nuxt/telemetry@2.2.0
            node_modules/@nuxt/telemetry
              @nuxt/telemetry@"^2.2.0" from nuxt@3.4.2
              node_modules/nuxt
                dev nuxt@"^3.4.2" from the root project
            @nuxt/kit@"^3.3.1" from @nuxtjs/tailwindcss@6.6.6
            node_modules/@nuxtjs/tailwindcss
              dev @nuxtjs/tailwindcss@"^6.1.3" from the root project
            @nuxt/kit@"3.4.2" from @nuxt/vite-builder@3.4.2
            node_modules/@nuxt/vite-builder
              @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
              node_modules/nuxt
                dev nuxt@"^3.4.2" from the root project
      peer @babel/core@"^7.0.0" from @babel/helper-compilation-targets@7.21.4
      peer @babel/core@"^7.0.0" from @babel/helper-create-class-features-plugin@7.21.4
      node_modules/@babel/helper-create-class-features-plugin
        @babel/helper-create-class-features-plugin@"^7.21.0" from @babel/plugin-transform-typescript@7.21.3
        node_modules/@babel/plugin-transform-typescript
          @babel/plugin-transform-typescript@"^7.20.7" from @vitejs/plugin-vue-jsx@3.0.1
          node_modules/@vitejs/plugin-vue-jsx
            @vitejs/plugin-vue-jsx@"^3.0.1" from @nuxt/vite-builder@3.4.2
            node_modules/@nuxt/vite-builder
              @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
              node_modules/nuxt
                dev nuxt@"^3.4.2" from the root project
      peer @babel/core@"^7.0.0-0" from @babel/plugin-syntax-typescript@7.21.4
      node_modules/@babel/plugin-syntax-typescript
        @babel/plugin-syntax-typescript@"^7.20.0" from @babel/plugin-transform-typescript@7.21.3
        node_modules/@babel/plugin-transform-typescript
          @babel/plugin-transform-typescript@"^7.20.7" from @vitejs/plugin-vue-jsx@3.0.1
          node_modules/@vitejs/plugin-vue-jsx
            @vitejs/plugin-vue-jsx@"^3.0.1" from @nuxt/vite-builder@3.4.2
            node_modules/@nuxt/vite-builder
              @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
              node_modules/nuxt
                dev nuxt@"^3.4.2" from the root project
      peer @babel/core@"^7.0.0-0" from @babel/plugin-transform-typescript@7.21.3
      node_modules/@babel/plugin-transform-typescript
        @babel/plugin-transform-typescript@"^7.20.7" from @vitejs/plugin-vue-jsx@3.0.1
        node_modules/@vitejs/plugin-vue-jsx
          @vitejs/plugin-vue-jsx@"^3.0.1" from @nuxt/vite-builder@3.4.2
          node_modules/@nuxt/vite-builder
            @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
            node_modules/nuxt
              dev nuxt@"^3.4.2" from the root project
      peer @babel/core@"^7.0.0-0" from @babel/plugin-syntax-jsx@7.21.4
      node_modules/@babel/plugin-syntax-jsx
        @babel/plugin-syntax-jsx@"^7.0.0" from @vue/babel-plugin-jsx@1.1.1
        node_modules/@vue/babel-plugin-jsx
          @vue/babel-plugin-jsx@"^1.1.1" from @vitejs/plugin-vue-jsx@3.0.1
          node_modules/@vitejs/plugin-vue-jsx
            @vitejs/plugin-vue-jsx@"^3.0.1" from @nuxt/vite-builder@3.4.2
            node_modules/@nuxt/vite-builder
              @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
              node_modules/nuxt
                dev nuxt@"^3.4.2" from the root project
      @babel/core@"^7.20.7" from @vitejs/plugin-vue-jsx@3.0.1
      node_modules/@vitejs/plugin-vue-jsx
        @vitejs/plugin-vue-jsx@"^3.0.1" from @nuxt/vite-builder@3.4.2
        node_modules/@nuxt/vite-builder
          @nuxt/vite-builder@"3.4.2" from nuxt@3.4.2
          node_modules/nuxt
            dev nuxt@"^3.4.2" from the root project
tenfei4 commented 1 year ago

I think it is caused by mysql2 v3.2.3, before upgrading from nuxt v3RC version to v3.2.x encountered similar problems, because mysql v2.18.1 caused by the reason, using mysql2 v3.2.3 to replace, after everything is normal, when upgrading from nuxt v3.2.x to v3.4.1 came out lru-cache problem. I hope to feed back the problem to you so that this kind of problem can be fundamentally solved.