pneutam
CDCloudflare Developers
•Created by jason on 8/9/2024 in #pages-help
`Error: Dynamic require of node:path is not supported` causes runtime error - how to troubleshoot?
I'm hitting this too @Jason with the CF Pages/SvelteKit combo. To state the obvious... it looks like it's because a dependency is found that imports a node library like
path
that is not compatible with the non-Node CF engine which is in force when running via wrangler pages dev
. I only see these errors on re-loading a route and not navigating from the root URL, so I've suspected this is SSR related since first seeing this.
Running code more on the client is one way to get around this. The nuclear option is setting ssr = false
and run your SvelteKit app as an SPA. I want to keep SSR and I had some components I wanted to dynamically load on the client anyways (tuning bundles) and doing so made the problem go away.
It's arisen again (why I read this thread) and looking more closely at the stack trace I can see my error is related to postcss and postcss-import in particular, which I can see does import "path". So my theory is that SvelteKit (or related dev plugins) use path
in SSR rendering which is what blows up the route. I saw there was an [alias]
option in wrangler.toml and I've been using pathe
as an alternative, however CF is complaining that it's not a valid pages configuration so I am still looking for a fix.8 replies