Nodejs_compat in Page Functions

Howdy all, I'm trying to deploy TinaCMS (https://github.com/tinacms/tinacms) self-hosted (https://tina.io/docs/reference/self-hosted/database-adapter/overview/) on Pages using Workers KV. | I set up a functions/graphql.ts to handle a graphql endpoint that imports some nodejs specific libraries from Tina. The deployments failed for it. There was a hint given by the error messages to add nodejs_compat as a compatiblity flag which I proceed to do in the Dashboard for both preview and prodution deployments but this did not seem to change when I retried the deployment. Similarly wrangler pages dev ./out --compatibility-date 21-11-2023 --compatibility-flags nodejs_compat does not seem to work end gives me the same error:
.....
✘ [ERROR] Could not resolve "path"

../node_modules/picomatch/lib/utils.js:3:21:
3 │ const path = require('path');
╵ ~~~~~~

The package "path" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.


✘ [ERROR] Could not resolve "crypto"

../node_modules/scmp/index.js:3:23:
3 │ const crypto = require('crypto')
╵ ~~~~~~~~

The package "crypto" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.


✘ [ERROR] Build failed with 53 errors:

../node_modules/@iarna/toml/parse-stream.js:4:23: ERROR: Could not resolve "stream"
../node_modules/@nodelib/fs.scandir/out/adapters/fs.js:4:19: ERROR: Could not resolve "fs"
../node_modules/@nodelib/fs.scandir/out/settings.js:3:21: ERROR: Could not resolve "path"
../node_modules/@nodelib/fs.stat/out/adapters/fs.js:4:19: ERROR: Could not resolve "fs"
../node_modules/@nodelib/fs.walk/out/providers/stream.js:3:25: ERROR: Could not resolve "stream"
...
.....
✘ [ERROR] Could not resolve "path"

../node_modules/picomatch/lib/utils.js:3:21:
3 │ const path = require('path');
╵ ~~~~~~

The package "path" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.


✘ [ERROR] Could not resolve "crypto"

../node_modules/scmp/index.js:3:23:
3 │ const crypto = require('crypto')
╵ ~~~~~~~~

The package "crypto" wasn't found on the file system but is built into node.
Add the "nodejs_compat" compatibility flag to your Pages project to enable Node.js compatibility.


✘ [ERROR] Build failed with 53 errors:

../node_modules/@iarna/toml/parse-stream.js:4:23: ERROR: Could not resolve "stream"
../node_modules/@nodelib/fs.scandir/out/adapters/fs.js:4:19: ERROR: Could not resolve "fs"
../node_modules/@nodelib/fs.scandir/out/settings.js:3:21: ERROR: Could not resolve "path"
../node_modules/@nodelib/fs.stat/out/adapters/fs.js:4:19: ERROR: Could not resolve "fs"
../node_modules/@nodelib/fs.walk/out/providers/stream.js:3:25: ERROR: Could not resolve "stream"
...
Any hints?
3 Replies
kian
kian13mo ago
nodejs_compat requires the imports to be prefixed with node: https://developers.cloudflare.com/workers/runtime-apis/nodejs/
zchr
zchrOP13mo ago
Aahhh didn't notice that in the docs. Ok, so i guess monkey patching or rewriting on my end 🙂 Thanks 🙂
zchr
zchrOP13mo ago
I posted a Pull Request to add this information to the error message 😄 https://github.com/cloudflare/workers-sdk/pull/4485
GitHub
Add info about node:${module} syntax for nodejs_compat by zmilona...
Fixes # [insert GH or internal issue number(s)]. What this PR solves / how to test: This updates the error message to point the user that they might be missing node: in the module name for the impo...
Want results from more Discord servers?
Add your server