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

fix: Check if path segments includes node_modules explicitly #74408

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

icyJoseph
Copy link
Contributor

What?

And edge case, as reported by #74404, where when the root dir name, contains the string node_modules, then Webpack errors are observed.

For example:

 ⨯ ./app/layout.tsx
Module parse failed: Unexpected token (1:12)
> import type { FC, PropsWithChildren } from "react";
| 
| const RootLayout: FC<PropsWithChildren> = ({

Why?

Although this is an edge case, it has been observed in user land, as per #74404

How?

Check if the node_modules is a path segment. Either of these works:

  return excludePath.split(path.sep).includes('node_modules')
  return excludePath.includes(path.sep + 'node_modules' + path.sep)
  return excludePath.includes('/node_modules/')

Or even a regexp match. I am just not sure about winOS and their path separators... and whether the path at this point is already normalised to /.

Fixes #74404

@ijjk
Copy link
Member

ijjk commented Dec 29, 2024

Allow CI Workflow Run

  • approve CI run for commit: 0eda7e3

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@Netail
Copy link
Contributor

Netail commented Dec 30, 2024

This change does not impact monorepo's right? Where the node_modules are sometimes located one or more directories above

@icyJoseph
Copy link
Contributor Author

icyJoseph commented Dec 30, 2024

@Netail I think it should not. The issue here was a false positive on files, that excluded them from the loader, because their path contains node_modules.

So the webpack process ended up seeing a TS file, where it expected JavaScript.

For example, if you make a project where you have app/my-node_modules/page.tsx, where maybe you wanted to show off the node_modules used by your project, you'd also encounter this issue.

This PR would fix that, but it wouldn't fix an even more adventurous, app/node_modules/page.tsx

Then I guess we need to make the check more robust, with a regexp, or process.cwd() 🤔~ maybe I'll push another commit soon ~ and maybe, no promises, a unit test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript/SWC not working when root directory name contains node_modules
3 participants