cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.72k stars 712 forks source link

🐛 BUG: Wrangler fails to run locally when Qwik City needs to reference external libraries #2598

Closed expo5170 closed 1 week ago

expo5170 commented 1 year ago

Which Cloudflare product(s) does this pertain to?

Wrangler

What version of Wrangler are you using?

2.8.1

What operating system are you using?

Windows

Describe the Bug

I'm using SSG to pre-render some blog posts at build time with Qwik. In order for this to work, I'm reading the .md files from the file system and after getting this build error

Cannot bundle Node.js built-in "fs" imported from "src\utils\posts.ts".
Consider disabling ssr.noExternal or remove the built-in dependency.

I followed the hint and declared fs as an external in adaptors/cloudflare-pages/vite.config.ts:

export default extendConfig(baseConfig, () => {
  return {
    build: {
      ssr: true,
      rollupOptions: {
        input: ['src/entry.cloudflare-pages.tsx', '@qwik-city-plan'],
🢂      external: ['fs'],
      },
    },
    plugins: [
      cloudflarePagesAdaptor({
        staticGenerate: true,
      }),
    ],
  };
});

The build now succeeds but when when I try to run wrangler pages dev ./dist I get:

X [ERROR] Could not resolve "fs"

    ../server/@qwik-city-plan.js:1:307:
      1 │ ...-89b65f67.js";import fs$1 from"fs";import require$$8 from"punyco...
        ╵                                  ~~~~

  The package "fs" wasn't found on the file system but is built into node.
  Add "node_compat = true" to your wrangler.toml file to enable Node compatibility.

X [ERROR] Build failed with 1 error:

  ../server/@qwik-city-plan.js:1:304: ERROR: Could not resolve "fs"
salihbenlalla commented 1 year ago

I'm facing the same problem, not for the .md files, but for a .json file that holds some data that i want to incorporate in some components at build time.

sacarvy commented 1 year ago

Is this bug got fixed, because facing difficulties in building with wrangler, myself

CarmenPopoviciu commented 6 months ago

Hi folks, are y'all still experiencing this issue with latest wrangler version? Does passing the --nodejs_compat flag to the pages dev command line solve it?

penalosa commented 1 week ago

We haven't heard from you in while so I'm going to close this issue for now. If you're still running into problems feel free to open a new issue with more details and we can investigate further.