Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript/SWC not working when root directory name contains node_modules #74404

Open
Netail opened this issue Dec 29, 2024 · 10 comments · May be fixed by #74408
Open

Typescript/SWC not working when root directory name contains node_modules #74404

Netail opened this issue Dec 29, 2024 · 10 comments · May be fixed by #74408
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js. TypeScript Related to types with Next.js.

Comments

@Netail
Copy link
Contributor

Netail commented Dec 29, 2024

Link to the code that reproduces this issue

https://github.com/Netail/repro-next-typescript-node_modules

To Reproduce

  1. Have the root directory of your project contain node_modules (In this case the default git clone name repro-next-typescript-node_modules)
  2. Install dependencies; yarn install
  3. Start the dev server; yarn dev
  4. Open localhost:3000 so it compiles the page
  5. See errors being thrown in the console regarding not being able to parse tokens. (e.g. import type or : 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

@Netail Netail added the bug Issue was opened via the bug report template. label Dec 29, 2024
@github-actions github-actions bot added SWC Related to minification/transpilation in Next.js. TypeScript Related to types with Next.js. labels Dec 29, 2024
@Netail Netail changed the title Typescript not working when directory has node_modules in it's name Typescript/SWC not working when root directory contains node_modules Dec 29, 2024
@icyJoseph
Copy link
Contributor

🤔 could you show a video of the issue happening?

https://stackblitz.com/github/Netail/repro-next-typescript-node_modules?file=README.md it works fine here, at least for me.

@Netail
Copy link
Contributor Author

Netail commented Dec 29, 2024

🤔 could you show a video of the issue happening?

stackblitz.com/github/Netail/repro-next-typescript-node_modules?file=README.md it works fine here, at least for me.

I assume stackblitz loads the content of a repo differently in, so the directory where the project gets downloaded in is not the same as the repository name. Or node_modules are not allowed to search outside of the directory, idk

repro-next-typescript-node_modules.-.Visual.Studio.Code.2024-12-29.22-49-11.mp4

@icyJoseph
Copy link
Contributor

The node_modules directory is right there:

Screenshot 2024-12-29 at 22 57 36

Could it be something with your system? you have win32, on a 64 bits platform? is that right? if you do node -p 'process.arch', does that match your OS?

@Netail
Copy link
Contributor Author

Netail commented Dec 29, 2024

It's not about the node_modules directory inside of the root directory. It's about the root directory name itself, which then contains the app, node_modules etc

repro-next-typescript-node_modules/ <---- This directory name
├─ node_modules/
├─ public/
│  ├─ .gitkeep
├─ app/
│  ├─ page.tsx
│  ├─ layout.tsx
│  ├─ favicon.ico
├─ .gitignore
├─ next.config.js
├─ package.json
├─ README.md
├─ tsconfig.json
├─ yarn.lock

Happens on both macos & windows 10

@icyJoseph
Copy link
Contributor

Oh no, uff, so the issue is Typescript/SWC not working when root directory name contains node_modules

Alright, that's not good... let me do some quick research

@Netail Netail changed the title Typescript/SWC not working when root directory contains node_modules Typescript/SWC not working when root directory name contains node_modules Dec 29, 2024
@Netail
Copy link
Contributor Author

Netail commented Dec 29, 2024

Yes 😅, I see the confusion there. I first had something regarding the name in the title Typescript not working when directory has node_modules in it's name, but this felt a bit too long. So accidentally pruned this crucial keyword

@Netail
Copy link
Contributor Author

Netail commented Dec 29, 2024

Alright, that's not good... let me do some quick research

I mean it's quite an edge case, who would add node_modules in the name of their root directory in a real project? I only stumbled upon it because I was working on a different repro.

@icyJoseph
Copy link
Contributor

Ok, I think I've got the error narrowed down, let me try to see if I can make a PR.

@icyJoseph
Copy link
Contributor

Here ya go, #74408 - it was introduced when these improvements where made, #62005

@Netail
Copy link
Contributor Author

Netail commented Dec 29, 2024

Awesome, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js. TypeScript Related to types with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants