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

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

Open
hmingv opened this issue Mar 12, 2024 · 8 comments
Open

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

hmingv opened this issue Mar 12, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@hmingv
Copy link

hmingv commented Mar 12, 2024

Environment

  • Operating System: Windows_NT
  • Node Version: v20.1.0
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.3
  • Package Manager: [email protected]
  • Builder: -
  • User Config: vite, routeRules, typescript, modules, image, runtimeConfig, app, postcss, components, css, nitro
  • Runtime Modules: [email protected], @nuxt/[email protected], @nuxtjs/[email protected]
  • Build Modules: -

Describe the bug

Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/[email protected]/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

@hmingv hmingv added the bug Something isn't working label Mar 12, 2024
@jonathanwilke
Copy link

Having the same issue.

@giacomocerquone
Copy link

it's almost identical to #68 since I have the very same problem with pnpm but not with yarn

@Diizzayy do you have any idea?

@Isengo1989
Copy link

Same here

@m0nch1
Copy link
Contributor

m0nch1 commented May 29, 2024

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
Copy link

manniL commented May 29, 2024

specifying shamefully-hoist=true in .npmrc might help

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

@iegik
Copy link

iegik commented Jul 15, 2024

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:
lquixada/cross-fetch#177 (comment)

Example:

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

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

@KillerJulian
Copy link

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
Copy link

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
            ]
        }
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants