faunadb-js
faunadb-js copied to clipboard
The package "http2" wasn't found on the file system but is built into node
Description
I'm trying to use faunadb in a Remix project with Cloudflare Workers as a deployment method, but when I'm trying to build or run a local dev server I get the following error:
X [ERROR] Could not resolve "http2"
node_modules/.pnpm/[email protected]/node_modules/faunadb/src/_http/http2Adapter.js:2:20:
2 │ var http2 = require('http2')
╵ ~~~~~~~
The package "http2" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
Stack trace:
Build failed with 1 error:
node_modules/.pnpm/[email protected]/node_modules/faunadb/src/_http/http2Adapter.js:2:20: ERROR: Could not resolve "http2"
Error
at Object.onBuildFailure (D:\Dev\Github\faunadb-cloudflare-workers-http2-issue\node_modules\.pnpm\@[email protected]_sfoxds7t5ydpegc3knd667wn6m\node_modules\@remix-run\dev\dist\cli\commands.js:167:13)
at buildEverything (D:\Dev\Github\faunadb-cloudflare-workers-http2-issue\node_modules\.pnpm\@[email protected]_sfoxds7t5ydpegc3knd667wn6m\node_modules\@remix-run\dev\dist\compiler.js:287:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.build (D:\Dev\Github\faunadb-cloudflare-workers-http2-issue\node_modules\.pnpm\@[email protected]_sfoxds7t5ydpegc3knd667wn6m\node_modules\@remix-run\dev\dist\compiler.js:107:3)
at async Object.build (D:\Dev\Github\faunadb-cloudflare-workers-http2-issue\node_modules\.pnpm\@[email protected]_sfoxds7t5ydpegc3knd667wn6m\node_modules\@remix-run\dev\dist\cli\commands.js:162:3)
at async Object.run (D:\Dev\Github\faunadb-cloudflare-workers-http2-issue\node_modules\.pnpm\@[email protected]_sfoxds7t5ydpegc3knd667wn6m\node_modules\@remix-run\dev\dist\cli\run.js:479:7)
Steps to reproduce
Reproduction repo: https://github.com/mccuna/faunadb-cloudflare-workers-http2-issue
-
npm install
-
npm run build
(the issue reproduces when runningnpm run dev:remix
too, so it's not something related to the production build itself)
Extra notes
The application I'm working on makes use of 2 Cloudflare Workers:
- Cloudflare Worker A that uses the Service Worker syntax and runs the Remix app powered by faunadb
- Cloudflare Worker B that uses the Module Worker syntax and contains only faunadb interactions and 3rd party API calls
The Cloudflare Worker B using the Module Worker syntax has type: "module"
in package.json
and in this one, faunadb works perfectly fine.
Internal ticket number is FE-2503
Which version of Node.js, npm
, and pnpm
are you running?
Since pnpm
tries to dedupe all of the Node modules installed on a system, you may be encountering a limitation where pnpm
cannot yet properly handle Node.js's "built-in" modules.
To test that theory, can you replace your pnpm
use with npm
? If that works, then it might be worth filing an issue with the pnpm
project.
I've tried deleting the node_modules
and using npm
, but unfortunately the issue persists.
The versions I'm using are:
-
node
:18.4.0
-
pnpm
:7.5.0
-
npm
:8.12.1
I believe the problem is related to the way the app bundle is created. I've put together a dummy repo with Cloudflare Workers & faunadb
(https://github.com/mccuna/faunadb-cloudflare-worker) and it seems that:
- if
wrangler.toml
hasmain = src/index.ts
andwrangler
handles the bundling, then then a similar error occurs
X [ERROR] [plugin checkForNodeBuiltins] Detected a Node builtin module import while Node compatibility is disabled.
Add node_compat = true to your wrangler.toml file to enable Node compatibility.
node_modules/faunadb/src/_http/fetchAdapter.js:46:16:
46 │ : require('http')
╵ ~~~~~~
This error came from the "onResolve" callback registered here:
node_modules/wrangler/wrangler-dist/cli.js:121430:11:
121430 │ build6.onResolve({
- if
wrangler.toml
hasmain = "build/index.js"
and I bundle the worker myself usingesbuild
andformat:"esm"
. Then everything is ok
Facing the same error when using the latest fresh install of Remix with the target set as Cloudflare Workers.
Same here, whatever options ES Build is using for Wrangler 2 is tripping over Fauna
I notice that there is a PR that adds support for Cloudflare Module Workers. This PR has – sadly – not been merged yet.
Maybe this change will correct the problem with the Fauna driver?
I am not sure, but it could be that this problem is two-fold. So to get the Fauna driver to work with Remix using Cloudflare Workers, two issues need to be addressed:
- Remix needs to use Cloudflare Module Worker and not Service Worker like today.
- Fauna needs to provide an EMS serverless driver like PlanetScale does.
Still facing the same problem. Would be nice if there is at least some patch that we can add locally to make it work with wrangler2
Have you tried to do with Remix and Cloudfare Pages? (not CF workers)
No, my production application is built with cloudflare workers and also I want to make use of Service Bindings. So, moving to cloudflare pages is a no-go for me at this time.
I want to use service bindings which will only work with Wrangler2, but wrangler2 doesn’t work with Fauna.
The latest version of Wrangler 2 (v2.9.1+) is compatible with the JS driver. But we are looking into what we can do to help with the fact that the default setup for Cloudflare and Remix is not working.
cc: @Shadid12