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

posthog-node@4.5 breaks build on SvelteKit for Cloudflare #395

Closed
1 of 4 tasks
ccremer opened this issue Feb 15, 2025 · 4 comments
Closed
1 of 4 tasks

posthog-node@4.5 breaks build on SvelteKit for Cloudflare #395

ccremer opened this issue Feb 15, 2025 · 4 comments
Labels
bug Something isn't working Error Tracking nodejs

Comments

@ccremer
Copy link

ccremer commented Feb 15, 2025

Bug description

> Using @sveltejs/adapter-cloudflare
✘ [ERROR] Could not resolve "node:fs"

    node_modules/posthog-node/lib/index.esm.js:2:33:
      2 │ import { createReadStream } from 'node:fs';
        ╵                                  ~~~~~~~~~

  Cannot use "node:fs" when deploying to Cloudflare.


✘ [ERROR] Could not resolve "node:readline"

    node_modules/posthog-node/lib/index.esm.js:3:32:
      3 │ import { createInterface } from 'node:readline';
        ╵                                 ~~~~~~~~~~~~~~~

  Cannot use "node:readline" when deploying to Cloudflare.

How to reproduce

  1. Have a SvelteKit project
  2. Use adapter-cloudflare and posthog-node
  3. Import posthog-node somewhere in code
  4. npm run build

Related sub-libraries

  • All of them
  • posthog-web
  • posthog-node
  • posthog-react-native

Additional context

Version 4.4.1 worked just fine.

@ccremer ccremer added the bug Something isn't working label Feb 15, 2025
@marandaneto
Copy link
Member

@PostHog/team-error-tracking

@ccremer
Copy link
Author

ccremer commented Feb 17, 2025

I have this nodejs_compat flag already enabled, both in wrangler.toml, and in the dashboard.

compatibility_date = "2024-11-11"
compatibility_flags = [ "nodejs_compat" ]

Image

However, I've found out that with adapter-cloudflare@4.9.0 it doesn't build, but it does @5.0.3.
I'm guessing since 5.0.0 node support is much better, but it might be relevant to mention the minimum versions in your docs as well.

Anyway, it works for me now. Thanks!

@ccremer ccremer closed this as completed Feb 17, 2025
@ccremer
Copy link
Author

ccremer commented Feb 17, 2025

Hm, maybe I closed it prematurely...
It builds, locally and in CF, but I still can't get a deployment up:

19:50:33.507 | ✓ built in 14.93s
19:50:33.507 |  
19:50:33.508 | Run npm run preview to preview your production build locally.
19:50:33.508 |  
19:50:33.508 | > Using @sveltejs/adapter-cloudflare
19:50:33.515 | ✔ done
19:50:33.665 | Finished
19:50:34.585 | Checking for configuration in a Wrangler configuration file (BETA)
19:50:34.586 |  
19:50:34.587 | Found wrangler.toml file. Reading build configuration...
19:50:35.683 | A wrangler.toml file was found but it does not appear to be valid. Did you mean to use wrangler.toml to configure Pages? If so, then make sure the file is valid and contains the `pages_build_output_dir` property. Skipping file and continuing.
19:50:35.683 | Found _worker.js in output directory. Uploading.
19:50:35.690 | ⛅️ wrangler 3.101.0
19:50:35.691 | -------------------
19:50:36.933 | ✨ Compiled Worker successfully
19:50:38.050 | Found _routes.json in output directory. Uploading.
19:50:38.062 | Validating asset output directory
19:50:40.685 | Deploying your site to Cloudflare's global network...
19:50:42.404 | Parsed 2 valid header rules.
19:50:43.877 | Uploading... (45/64)
19:50:44.299 | Uploading... (51/64)
19:50:44.528 | Uploading... (57/64)
19:50:44.581 | Uploading... (64/64)
19:50:44.582 | ✨ Success! Uploaded 19 files (45 already uploaded) (1.29 sec)
19:50:44.582 |  
19:50:44.973 | ✨ Upload complete!
19:50:46.908 | Uploading to dependency cache
19:50:46.962 | Skipping build output cache as it's not supported for your project
19:50:48.156 | Success: Dependencies uploaded to build cache.
19:50:49.073 | Success: Assets published!
19:50:50.980 | Error: Failed to publish your Function. Got error: Uncaught Error: No such module "node:fs".   imported from "functionsWorker-0.9051079702222944.js"

But I'm not sure what the problem is, could be a bug on CF as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Error Tracking nodejs
Projects
None yet
Development

No branches or pull requests

3 participants