Skip to content

docs: add missing package.json "type": "module" step to TypeScript in… - #2464

Open
jnzlab wants to merge 1 commit into
expressjs:mainfrom
jnzlab:patch-1
Open

jnzlab wants to merge 1 commit into
expressjs:mainfrom
jnzlab:patch-1

Conversation

@jnzlab

@jnzlab jnzlab commented Jul 30, 2026

Copy link
Copy Markdown

Description

The TypeScript setup section provides a tsconfig.json using "module": "nodenext" and demonstrates ESM import syntax in src/app.ts, but doesn't mention that package.json also needs "type": "module" set. Without it, TypeScript treats .ts files as CommonJS by default and throws ECMAScript imports and exports cannot be written in a CommonJS file under 'verbatimModuleSyntax'. (ts1295) when following the guide as written. This adds the missing step so the example works out of the box.

Changes

  • Added a new step between the middleware-types warning and the tsconfig.json block explaining that "module": "nodenext" requires package.json to declare "type": "module"
  • Included a package.json code snippet showing the required field
  • Added a warning callout explaining the exact error users will hit if this step is skipped

Type of change

  • Documentation fix/improvement

…stall guide

The TypeScript setup section provides a tsconfig.json using "module": "nodenext" and demonstrates ESM import syntax in src/app.ts, but doesn't mention that package.json also needs "type": "module" set. Without it, TypeScript treats .ts files as CommonJS by default and throws ECMAScript imports and exports cannot be written in a CommonJS file under 'verbatimModuleSyntax'. (ts1295) when following the guide as written. This adds the missing step so the example works out of the box.

Signed-off-by: Jameel Ahmad <jameelahmad221b@gmail.com>
@jnzlab
jnzlab requested a review from a team as a code owner July 30, 2026 08:47
@netlify

netlify Bot commented Jul 30, 2026

Copy link
Copy Markdown

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit bd52689
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/6a6b0fc1770a8500080d383b
😎 Deploy Preview https://deploy-preview-2464--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 98 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@krzysdz

krzysdz commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

There is also another problem - while Node.js can detect and run .js/.ts files as ES Modules, npm init sets "type": "commonjs" by default, effectively blocking the detection mechanism.

@krzysdz krzysdz added docs Issues/pr concerning content typescript labels Jul 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Issues/pr concerning content typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants