Skip to content

typescript should be added to dependencies not devDependencies since it is used to parse the next.config.ts #81798

@modten

Description

@modten

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/late-paper-vwtflr?workspaceId=ws_YRKBG6vgzA8hNCZ8dUsZEh

To Reproduce

In our workflow, we remove the devDependencies during the CI phase to reduce the size of the final deploy image.

npx create-next-app@latest 
npm install
npm run build
npm prune --production
npm start

It reports the following problem

➜  workspace git:(main) ✗ npm start       

> start
> next start

   ▲ Next.js 15.4.2-canary.7
   - Local:        http://localhost:3000
   - Network:      http://192.168.241.2:3000

 ✓ Starting...
 ⚠ Installing TypeScript as it was not found while loading "next.config.ts".

Installing devDependencies (npm):
- typescript


added 5 packages, and audited 35 packages in 1s

8 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

 ⨯ Failed to load next.config.ts, see more info here https://nextjs.org/docs/messages/next-config-error
[Error: Cannot find module 'typescript'
Require stack:
- /project/workspace/node_modules/next/dist/build/next-config-ts/transpile-config.js
- /project/workspace/node_modules/next/dist/server/config.js
- /project/workspace/node_modules/next/dist/cli/next-test.js
- /project/workspace/node_modules/next/dist/bin/next] {
  code: 'MODULE_NOT_FOUND',
  requireStack: [Array]
}

Current vs. Expected behavior

In version 15.4.1, due to changes in the transpileConfig file #79055, next now relies on typescript to parse next.config.ts. In this case, typescript should be placed in dependencies to avoid being cleaned up.

And installing dependencies at runtime does not seem to be a good practice. In production environments, it is often forbidden to connect to the public network or perform any operations that change the deployed artifacts.

Why not compile next.config.ts into next.config.js when executing the build command? Starting from Node.js 22, typescript file parsing is natively supported, which may be another solution.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.4.2-canary.7 // Latest available version is detected (15.4.2-canary.7).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

create-next-app

Which stage(s) are affected? (Select all that apply)

next start (local)

Additional context

No response

NEXT-4657

Metadata

Metadata

Assignees

Labels

create-next-appRelated to our CLI tool for quickly starting a new Next.js application.linear: nextConfirmed issue that is tracked by the Next.js team.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions