nodejs_compat compatibility-flags flags not working for Pages functions
I've added nodejs_compat to both prod and preview in the UI but every deploy fails with these errors
Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.
I can run it fine locally using --node-compat
4 Replies
locally, if I don't include node-compat I get the same error as when I deploy it. It feels the flag is not working when deploying
I'm trying to just use pg like in one of the examples
that's the error when I deploy, when it tries to build
nodejs_compat
is runtime apis only. They're not built into your code, but simply resolve at runtime execution. The key takeaway here is:
Node.js APIs are available under the node:
prefix, and this prefix must be used when importing modules, both in your code and the npm packages you depend on.
https://developers.cloudflare.com/workers/runtime-apis/nodejs
--node-compat
uses polyfill to recreate those functions. These get bundled into your code but that makes your code a bit biggerNode.js compatibility · Cloudflare Workers docs
Most Workers import one or more packages of JavaScript or TypeScript code from npm as dependencies in package.json. Many of these packages rely on …
Based on your logs, it's looking for the node imports without the
node:
prefixso we can't use postgres from functions?
I'm still confused why I can use --node-compat locally to get it to work but not when i deploy