unjs / giget

✨ Download templates and git repositories with pleasure!
MIT License
425 stars 37 forks source link

Cannot resolve "node-fetch-native/native/proxy" from "..." and externals are not allowed! #140

Closed vejja closed 6 months ago

vejja commented 6 months ago

Environment

giget 1.2.1 Node 18 Nuxt 3.8.2, 3.9.0, 3.9.1 Nitro 2.8.1

Reproduction

Sorry unable to provide repro as this only appears in workers environment This was reported on Cloudflare, Vercel

Does not appear in NodeJS, local environments

Describe the bug

Initial bug report was filed in Nuxt-Security there We initially thought the issue was on our side but were unable to reproduce

Then one user filed logs, and we realized the error was triggered by giget while trying to use node-fetch-native in Workers environments

Additional context

This looks like a version dependency mismatch on node-fetch-native This is very strange because package managers should usually be able to resolve the correct version without any issue In fact, in NodeJS environments the issue does not exist

However for some unknown reason, it seems to affect Workers environment

Logs

(node-resolve plugin) Could not resolve import "node-fetch-native/native/proxy" in /opt/_work/myproject/node_modules/.pnpm/giget@1.2.1/node_modules/giget/dist/index.mjs using exports defined in /opt/_work/myproject/node_modules/.pnpm/node-fetch-native@1.6.1/node_modules/node-fetch-native/package.json.
Error:  [nitro] Error: Cannot resolve "node-fetch-native/native/proxy" from "/opt/_work/myproject/node_modules/.pnpm/giget@1.2.1/node_modules/giget/dist/index.mjs" and externals are not allowed!

undefined
Error:  Cannot resolve "node-fetch-native/native/proxy" from "/opt/_work/myproject/node_modules/.pnpm/giget@1.2.1/node_modules/giget/dist/index.mjs" and externals are not allowed!
  at Object.resolveId (node_modules/.pnpm/nitropack@2.8.1/node_modules/nitropack/dist/shared/nitro.4ea992bc.mjs:1973:17)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:18542:28)
  at async resolveId (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:17211:26)
  at async ModuleLoader.resolveId (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:17625:15)
  at async Object.resolveId (node_modules/.pnpm/@rollup+plugin-commonjs@25.0.7_rollup@4.9.2/node_modules/@rollup/plugin-commonjs/dist/es/index.js:588:10)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:18542:28)
  at async resolveId (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:17211:26)
  at async ModuleLoader.resolveId (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:17625:15)
  at async PluginDriver.hookFirstAndGetPlugin (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:18542:28)
  at async resolveId (node_modules/.pnpm/rollup@4.9.2/node_modules/rollup/dist/es/shared/node-entry.js:17211:26) 

Error:  Cannot resolve "node-fetch-native/native/proxy" from "/opt/_work/myproject/node_modules/.pnpm/giget@1.2.1/node_modules/giget/dist/index.mjs" and externals are not allowed!
 ELIFECYCLE  Command failed with exit code 1.
Error: Process completed with exit code 1.
pi0 commented 6 months ago

Hi. Please try recreating your lockfile using npx nuxi upgrade --force this ensures to use latest compatible node-fetch-native build. unofrotounatly nothing we can do in giget itself to mitigate package manager hoisting issues.

tkjaergaard commented 6 months ago

I'm experiencing this bug as well in a non-nuxt Bun project.

$ bun build src/index.ts --outdir dist --target node
11 | import { fetch } from 'node-fetch-native/proxy';
              ^
error: No matching export in "node_modules/node-fetch-native/dist/proxy.cjs" for import "fetch"
    at /Users/thomaskjaergaard/projects/internal/wah-cli-v3/node_modules/giget/dist/index.mjs:11:10
error: script "build" exited with code 1
pi0 commented 6 months ago

@tkjaergaard can you please share your project or a reproduction? 🙏🏼

tkjaergaard commented 6 months ago

@pi0

Bun: 1.0.25

Git repo: https://github.com/tkjaergaard/giget-bun-reproduction

Steps to reproduce

  1. Clone repository
  2. Install Bun version 1.0.25 (https://bun.sh)
  3. Run bun install to install dependencies
  4. Run build command
    $ bun build index.ts --outdir=dist --target=node

Error

11 | import { fetch } from 'node-fetch-native/proxy';
              ^
error: No matching export in "node_modules/node-fetch-native/dist/proxy.cjs" for import "fetch"
    at /Users/thomaskjaergaard/projects/internal/giget-bun-reproduction/node_modules/giget/dist/index.mjs:11:10
pi0 commented 6 months ago

Thanks. I will investigate in https://github.com/unjs/giget/issues/145 👍🏼