Skip to content

fix: resolve production MIME type error and add Netlify build config#51

Merged
jbarson merged 4 commits intomainfrom
claude/suggest-improvement-CR4aY
Mar 8, 2026
Merged

fix: resolve production MIME type error and add Netlify build config#51
jbarson merged 4 commits intomainfrom
claude/suggest-improvement-CR4aY

Conversation

@jbarson
Copy link
Owner

@jbarson jbarson commented Mar 8, 2026

Summary

  • Fixes a production MIME type error where browsers rejected scripts/app.ts served with text/vnd.trolltech.linguist instead of application/javascript
  • Adds netlify.toml so Netlify runs npm run build and serves the compiled dist/ output (where .ts references are replaced by .js bundles)
  • Adds a dev-server middleware plugin in vite.config.js as a belt-and-braces fix for local development on OS configurations that misregister .ts MIME types

Root cause

Netlify was serving the raw source files directly (no build configured), so the browser received scripts/app.ts with the OS-level MIME type. The fix is to serve the built output instead.

Test plan

  • Merge to main and verify Netlify picks up the build config and deploys from dist/
  • Confirm the MIME type error no longer appears in production
  • CI lint/test/build passes

🤖 Generated with Claude Code

jbarson and others added 3 commits March 7, 2026 18:44
Some OS configurations (macOS, some Linux distros) register .ts files
as text/vnd.trolltech.linguist or video/mp2t. Vite 7.3.x (updated by
npm audit fix) no longer overrides this, causing browsers to reject
TypeScript module scripts with a strict MIME type error.

Add a lightweight dev-server middleware plugin that sets
Content-Type: application/javascript for any .ts request.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The production MIME type error (text/vnd.trolltech.linguist for .ts
files) occurs because raw source files were being served. The Vite
build compiles everything to dist/ with .js bundles, eliminating the
issue entirely.

Add an upload-pages-artifact step (main branch only) and a deploy job
that publishes dist/ to GitHub Pages after a successful build-and-test.
PRs still run lint/test/build but do not deploy.

Note: GitHub Pages must be configured to deploy from GitHub Actions
in the repo Settings → Pages → Source.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without a build config Netlify was serving raw source files, causing
browsers to reject scripts/app.ts with a MIME type error. Setting the
build command to 'npm run build' and publish dir to 'dist' means
Netlify serves the compiled JS bundles instead.

Also reverts the GitHub Pages deployment added in the previous commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 8, 2026 00:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a production deployment issue where TypeScript source was being served directly (and with an incorrect MIME type) by configuring Netlify to build and publish Vite’s dist/ output, plus a small dev-server safeguard for .ts MIME handling.

Changes:

  • Add netlify.toml to run npm run build and publish dist/.
  • Add a Vite dev-server middleware plugin to force Content-Type: application/javascript for .ts requests.
  • Minor whitespace-only change in CI workflow.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
vite.config.js Adds a dev-server middleware plugin to force a safe JS MIME type for .ts module requests.
netlify.toml Configures Netlify to build the site and serve the compiled dist/ output.
.github/workflows/ci.yml No functional change (trailing newline/whitespace).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,3 @@
[build]
command = "npm run build"
publish = "dist"
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Netlify’s build image Node version needs to satisfy the repo’s Vite engine requirement. package-lock.json shows vite@7.3.1 requires Node ^20.19.0 || >=22.12.0; without pinning NODE_VERSION (or an .nvmrc/engines field), Netlify may default to an older Node 20 minor or Node 18 and the deploy/build will fail. Suggest adding [build.environment] NODE_VERSION = "20.19.0" (or a compatible 22.x) and aligning local/CI accordingly.

Suggested change
publish = "dist"
publish = "dist"
[build.environment]
NODE_VERSION = "20.19.0"

Copilot uses AI. Check for mistakes.
Vite 7.3.1 requires Node ^20.19.0 || >=22.12.0. Without pinning the
version Netlify may default to an older Node 20 minor or Node 18 and
the build would fail.

Resolves Copilot review comment on PR #51.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jbarson jbarson merged commit 8654bb6 into main Mar 8, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants