Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The package "http2" wasn't found on the file system but is built into node #649

Open
mccuna opened this issue Jul 20, 2022 · 11 comments
Open

Comments

@mccuna
Copy link

mccuna commented Jul 20, 2022

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

  1. npm install
  2. npm run build (the issue reproduces when running npm 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.

@github-actions
Copy link

Internal ticket number is FE-2503

@faunaee
Copy link
Contributor

faunaee commented Jul 20, 2022

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.

@mccuna
Copy link
Author

mccuna commented Jul 20, 2022

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 has main = src/index.ts and wrangler 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 has main = "build/index.js" and I bundle the worker myself using esbuild and format:"esm". Then everything is ok

@pbteja1998
Copy link

Facing the same error when using the latest fresh install of Remix with the target set as Cloudflare Workers.

@TriangularCube
Copy link

Same here, whatever options ES Build is using for Wrangler 2 is tripping over Fauna

@runarj
Copy link

runarj commented Dec 27, 2022

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?

@runarj
Copy link

runarj commented Jan 16, 2023

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:

  1. Remix needs to use Cloudflare Module Worker and not Service Worker like today.
  2. Fauna needs to provide an EMS serverless driver like PlanetScale does.

@pbteja1998
Copy link

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

@anurag-loco
Copy link

Have you tried to do with Remix and Cloudfare Pages? (not CF workers)

@pbteja1998
Copy link

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.

@ptpaterson
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants