Demo, all content is generated
Question

Exported Bolt project fails on Netlify, but runs fine inside Bolt

Solved · 351 views · asked by coop_builds · edited

Downloaded my project as zip, pushed to GitHub, connected Netlify. Build log:

$ tsc -b && vite build
src/pages/Admin.tsx(12,10): error TS6133: 'useEffect' is declared but its value is never read.
src/lib/api.ts(88,3): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
... 23 more
Build script returned non-zero exit code: 2

But in Bolt the app runs and I never saw any of these.

What I’ve tried

Set NODE_VERSION=20 on Netlify because a blog said so. Didn't change anything.

Comment
Does npm run build pass when you run it in Bolt's terminal? rafa_dev · edited
same errors there. never ran it before honestly coop_builds · edited

3 answers

Marked as helpful by the asker
rafa_dev · edited

Bolt's preview runs the dev server, which strips types without checking them. Netlify runs the build script, which starts with tsc -b and fails on any type error. So these errors were always there, you just never ran the build.

Order of work:

  1. Run npm run build locally (or in Bolt's terminal) so you see the same list.
  2. TS6133 (unused imports): harmless, delete the imports. Or set "noUnusedLocals": false in tsconfig.app.json if there are many.
  3. TS2345 and friends: real bugs, fix them. api.ts:88 passing a number where a string is expected will bite you at runtime.

Don't "fix" it by changing the build script to only vite build. It works, but you're shipping the bugs.

Comment
Fixed all 25. Two of them were actual bugs in the admin page, so thanks for the warning coop_builds · edited
The dev vs build difference explained a lot for me too thiago_n · edited
katja_s · edited

Make the build part of your routine: run npm run build before every push, or add a small GitHub Action that runs it on each pull request. Then Netlify is never the first to tell you.

Comment
added the action, it already caught one thing coop_builds · edited
priscila_m · edited

Also check your env vars on Netlify. Bolt's .env isn't in the zip, so after the build passes you'll get a blank site if VITE_ variables aren't set in Netlify's settings.

Comment