fix: resolve production MIME type error and add Netlify build config#51
fix: resolve production MIME type error and add Netlify build config#51
Conversation
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>
There was a problem hiding this comment.
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.tomlto runnpm run buildand publishdist/. - Add a Vite dev-server middleware plugin to force
Content-Type: application/javascriptfor.tsrequests. - 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" | |||
There was a problem hiding this comment.
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.
| publish = "dist" | |
| publish = "dist" | |
| [build.environment] | |
| NODE_VERSION = "20.19.0" |
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>
Summary
scripts/app.tsserved withtext/vnd.trolltech.linguistinstead ofapplication/javascriptnetlify.tomlso Netlify runsnpm run buildand serves the compileddist/output (where.tsreferences are replaced by.jsbundles)vite.config.jsas a belt-and-braces fix for local development on OS configurations that misregister.tsMIME typesRoot cause
Netlify was serving the raw source files directly (no build configured), so the browser received
scripts/app.tswith the OS-level MIME type. The fix is to serve the built output instead.Test plan
dist/🤖 Generated with Claude Code