Diizzayy / nuxt-graphql-client

⚡️ Minimal GraphQL Client + Code Generation for Nuxt3
https://nuxt-graphql-client.web.app
MIT License
357 stars 44 forks source link

JS error at index.ts 36:8 browser-ponyfill.js #473

Open hmingv opened 6 months ago

hmingv commented 6 months ago

Environment

Describe the bug

Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/cross-fetch@3.1.8/node_modules/cross-fetch/dist/browser-ponyfill.js?v=368afc8d' does not provide an export named 'default' (at index.ts:36:8)

image image

Expected behaviour

No errors

Reproduction

No response

Additional context

No response

Logs

No response

jonathanwilke commented 6 months ago

Having the same issue.

giacomocerquone commented 5 months ago

it's almost identical to https://github.com/Diizzayy/nuxt-graphql-client/issues/68 since I have the very same problem with pnpm but not with yarn

@Diizzayy do you have any idea?

Isengo1989 commented 5 months ago

Same here

m0nch1 commented 4 months ago

I'm not sure, but specifying shamefully-hoist=true in .npmrc might help.

The sample at https://nuxt-graphql-client.web.app/getting-started/quick-start#preview is working with pnpm and specifies these options.

ref: https://stackblitz.com/edit/nuxt-graphql?file=.npmrc

cc: @Diizzayy

manniL commented 4 months ago

specifying shamefully-hoist=true in .npmrc might help

That solves the issue. Might need to add explicit deps.

iegik commented 2 months ago

As I know, Nuxt and Next are the both client and server hybrid solutions and cross-fetch supposed to be a replacement (ponyfill) for a fetch. But, it isn't. Because Ponyfills are new, separate functions that are used to replace native ones, and Polyfills are add functionality, that not existed in the environment.

So, cross-fetch not only replaces the existed functionality, but also breaks types, expected behavior and add unexpected dependency.

As a solution - replace cross-fetch with dummy empty package as mentioned here: https://github.com/lquixada/cross-fetch/issues/177#issuecomment-2172981911

Example:

  "overrides": {
    "cross-fetch": {
      "import": "src/overrides/dummy.js"
    }
  }
// src/overrides/dummy.js
import 'esm';

export {}; // Empty export to prevent default behavior
KillerJulian commented 1 month ago

specifying shamefully-hoist=true in .npmrc might help

Original message

  "overrides": {
    "cross-fetch": {
      "import": "src/overrides/dummy.js"
    }
  }
// src/overrides/dummy.js
import 'esm';

export {}; // Empty export to prevent default behavior

Original message

Neither approach helped me with pnpm.

KillerJulian commented 1 month ago

Workaround

The following solution from Pull Request #498 solved the problem for me. Add the following to the ~/nuxt.config.ts:

export default defineNuxtConfig({
    // ...
    vite: {
        optimizeDeps: {
            include: [
                'nuxt-graphql-client > graphql-request' // Workaround for: https://github.com/Diizzayy/nuxt-graphql-client/issues/473
            ]
        }
    }
});