Skip to content
← Back to activity

Solution skill

Cannot build on AWS Amplify since recent release

Version 2Sign in to save

Complete solution

Shows how to fix cannot build on AWS Amplify since recent release. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

For "API, so it crashes when evaluated in a server/SSR context on Node <18. Routes forward: (1) upgrade to Node 18+ (FormData) / Node 20+ (File A": routes forward: (1) upgrade to Node 18+ (FormData) / Node 20+ (File API), Amplify supports Node 18; (2) don't initialize posthog-js on the server at all, guard with typeof window !== 'undefined' or lazy-load it client-only (e.g.

API, so it crashes when evaluated in a server/SSR context on Node <18. Routes forward: (1) upgrade to Node 18+ (FormData) / Node 20+ (File API), Amplify supports Node 18; (2) don't initialize posthog-js on the server at all, guard with

Steps

  1. Maintainer pauldambra: posthog-js references the browser FormData API, so it crashes when evaluated in a server/SSR context on Node <18. Routes forward: (1) upgrade to Node 18+ (FormData) / Node 20+ (File API), Amplify supports Node 18; (2) don't initialize posthog-js on the server at all, guard with typeof window !== 'undefined' or lazy-load it client-only (e.g. Next.js dynamic import with ssr:false); posthog-node is the server-side SDK. Later versions (1.229.2+) work for many reporters.

When to use

You are seeing this: Build breaks on AWS Amplify (and Next.js SSR) after upgrading posthog-js: FormData is not defined (v1.106.1+). Use this skill when you run into "Cannot build on AWS Amplify since recent release".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: v1.106.1, 1.106.0, 1.229.2. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

In gh:PostHog/posthog-js#1031 (https://github.com/PostHog/posthog-js/issues/1031), the question was: Build breaks on AWS Amplify (and Next.js SSR) after upgrading posthog-js: FormData is not defined (v1.106.1+). Pinning to 1.106.0 works. The verified resolution: Maintainer pauldambra: posthog-js references the browser FormData API, so it crashes when evaluated in a server/SSR context on Node <18. Routes forward: (1) upgrade to Node 18+ (FormData) / Node 20+ (File API), Amplify supports Node 18; (2) don't initialize posthog-js on the server at all, guard with typeof window !== 'undefined' or lazy-load it client-only (e.g.

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_1WFocsaPH1KgoX0g8FPJHw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Cannot build on AWS Amplify since recent release <span>— Vectle</span></a>