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

bug(pnpm): require() of ES Module #68

Closed oritwoen closed 2 years ago

oritwoen commented 2 years ago

With pnpm afterpnpm build and then pnpm preview crashes with strange errors. With yarn everything works fine.


[nuxt] [request error] require() of ES Module /home/ririen/Projekty/Project/Website/.output/server/node_modules/node-fetch/src/index.js from /home/ririen/Projekty/Project/Website/.output/server/node_modules/cross-fetch/dist/node-ponyfill.js not supported.
Instead change the require of index.js in /home/ririen/Project/Project/Website/.output/server/node_modules/cross-fetch/dist/node-ponyfill.js to a dynamic import() which is available in all CommonJS modules.
  at Object.<anonymous> (./server/node_modules/cross-fetch/dist/node-ponyfill.js:1:19)  
  at Object.<anonymous> (./server/node_modules/graphql-request/dist/index.js:84:34)  
  at async Promise.all (index 0)  
  at async ./server/chunks/handlers/renderer.mjs:11064:24  
  at async ./server/chunks/handlers/renderer.mjs:11120:64  
  at async ./server/node_modules/h3/dist/index.mjs:417:19  
  at async Server.nodeHandler (./server/node_modules/h3/dist/index.mjs:367:7)
DenisNikonov commented 2 years ago

i get this error with yarn after yarn preview or node .output/server/index.mjs

- Operating System: `Darwin`
- Node Version:     `v18.1.0`
- Nuxt Version:     `3.0.0-rc.3`
- Package Manager:  `yarn@1.22.15`
- Builder:          `vite`
- User Config:      `modules`, `runtimeConfig`, `nitro`, `vite`, `sourceMap`
- Runtime Modules:  `nuxt-graphql-client@0.0.24`
- Build Modules:    `-`
(node:95748) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/denisnikonov/projects/nuxt-text/.output/server/node_modules/node-fetch/src/index.js:9
import http from 'node:http';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)

Node.js v18.1.0
Diizzayy commented 2 years ago

@ririen @DenisNikonov This was addressed upstream and should now be working without issue for you.

be sure to delete your lockfile (yarn.lock or package-lock.json) and ensure that your new lockfile uses unenv >= 0.5.2 & nitropack => 0.4.4, this can be verified for yarn by running yarn why unenv

DenisNikonov commented 2 years ago

@Diizzayy It works! Thank you for your work