qwik icon indicating copy to clipboard operation
qwik copied to clipboard

Cannot bundle Node.js built-in "node:http", due to node-fetch dep

Open yoroshikun opened this issue 3 years ago • 5 comments

Qwik Version

v0.9.0

Operating System (or Browser)

OSX

Node Version (if applicable)

v16.3.0

Which component is affected?

Qwik Rollup / Vite plugin

Expected Behaviour

The preview command builds and previews the application

Actual Behaviour

The preview command fails with

[commonjs--resolver] Cannot bundle Node.js built-in "node:http" imported from "node_modules/node-fetch/src/index.js". Consider disabling ssr.noExternal or remove the built-in dependency.
error during build:
Error: Cannot bundle Node.js built-in "node:http" imported from "node_modules/node-fetch/src/index.js". Consider disabling ssr.noExternal or remove the built-in dependency.
    at error (file:///Users/yoroshi/projects/web/qwik-app/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
    at throwPluginError (file:///Users/yoroshi/projects/web/qwik-app/node_modules/rollup/dist/es/shared/rollup.js:21781:12)
    at Object.error (file:///Users/yoroshi/projects/web/qwik-app/node_modules/rollup/dist/es/shared/rollup.js:22503:20)
    at Object.resolveId (file:///Users/yoroshi/projects/web/qwik-app/node_modules/vite/dist/node/chunks/dep-a713b95d.js:34356:34)
    at Object.handler (file:///Users/yoroshi/projects/web/qwik-app/node_modules/vite/dist/node/chunks/dep-a713b95d.js:45961:19)
    at file:///Users/yoroshi/projects/web/qwik-app/node_modules/rollup/dist/es/shared/rollup.js:22710:40

Occurs after Vite ✓ Built client modules

Additional Information

To reproduce simply create a new qwik app using the creator and add a integration with cloudflare-pages or netlify-edge

npm create qwik@latest
# Create basic
cd qwik-app
npm run qwik add cloudflare-pages # or netlify-edge
npm run preview

This only seems to effect the edge function integrations.

yoroshikun avatar Sep 22 '22 08:09 yoroshikun

I have the same issue

The repo is here: https://github.com/philwolstenholme/lasttramfrom-qwik

philwolstenholme avatar Sep 23 '22 15:09 philwolstenholme

I had the same issue

The repo is here: https://github.com/gang-of-front/realworld-qwik

I changed vite.config.ts and add "type": "module" in package.json the preview works for me

// => vite.config.ts || noExternal: undefined

export default defineConfig(() => {
  return {
    ssr: { target: "webworker", noExternal: undefined },
    plugins: [qwikCity(), qwikVite(), tsconfigPaths()],
  };
});
{
  "name": "my-qwik-basic-starter",
  "description": "Recommended for your first Qwik app",
  "engines": {
    "node": ">=15.0.0"
  },
  "type": "module",
}

rafaellucio avatar Sep 30 '22 01:09 rafaellucio

just remove the netlifyEdge(...) config from vite.config.ts file is sufficient to overcome it on my side 👍

zanettin avatar Oct 12 '22 13:10 zanettin

I'm experiencing the same with 0.11.1.

Rafael's suggestion didn't fix it for me

guilhermehto avatar Oct 17 '22 16:10 guilhermehto

Having the same issue on 0.11.1

sameerxanand avatar Oct 18 '22 23:10 sameerxanand

Thanks for opening the issue. With how how the vite.config was being shared caused issues similar to this, which is why the latest updates recommends using the adaptors and vite configs specifically for each server. I verified the updates worked on the example repo from @rafaellucio.

  1. Update to the latest version of @builder.io/qwik and @builder.io/qwik-city
  2. Run npm run qwik add
  3. Add the "Adaptor" you'll be using, such as "Adaptor: Cloudflare Pages (serverless)"
  4. A new vite config will be created: adaptors/cloudflare-pages/vite.config.ts
  5. Your package.json build.server will be updated to vite build -c adaptors/cloudflare-pages/vite.config.ts

Additionally, in the root vite.config.ts, you'll be able to remove the ssr property, since it's now included in the cloudflare specific vite config:

export default defineConfig(() => {
  return {
-    ssr: { target: "webworker", noExternal: true },
    plugins: [qwikCity(), qwikVite(), tsconfigPaths()],
  };
});

Hope that helps and please reopen a new issue if you're still have troubles. Thanks

adamdbradley avatar Oct 31 '22 19:10 adamdbradley