Typescript/SWC not working when root directory name contains node_modules
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://github.com/Netail/repro-next-typescript-node_modules
To Reproduce
- Have the root directory of your project contain
node_modules(In this case the default git clone namerepro-next-typescript-node_modules) - Install dependencies;
yarn install - Start the dev server;
yarn dev - Open
localhost:3000so it compiles the page - See errors being thrown in the console regarding not being able to parse tokens. (e.g.
import typeor: FC)
Current vs. Expected behavior
When the root directory contains the word node_modules, SWC fails to transpile the typescript files, while the rest seems to be working fine. I expected Typescript to be working fine, regardless of the root directory name
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Home
Available memory (MB): 32702
Available CPU cores: 8
Binaries:
Node: 22.11.0
npm: 10.9.0
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
next: 15.1.3 // Latest available version is detected (15.1.3).
eslint-config-next: N/A
react: 19.0.0
react-dom: 19.0.0
typescript: 5.5.4
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
TypeScript, SWC
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local)
Additional context
I was testing another bug regarding node_modules & bundling and called the directory something with node_modules, this resulted in some "Module parse failed: Unexpected token" errors, which took me a few hours to realise it was because of the root directory name
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository, run yarn install and yarn dev, and confirm the parse errors when the project root name contains node_modules. Trace how the dev and build stages locate and transpile TypeScript through SWC; done means both next dev and next build compile the TypeScript files successfully from such a directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, react, typescript
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100