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

Tsconfig.json does not resolve paths with dashes "-" in folder name #42913

Closed
cbdeveloper opened this issue Feb 22, 2021 · 6 comments
Closed
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@cbdeveloper
Copy link

cbdeveloper commented Feb 22, 2021

Bug Report

πŸ”Ž Search Terms

tsconfig.json, path, resolve, include, exclude, dash

πŸ•— Version & Regression Information

[email protected] installed globally on VSCode Windows 10.

⏯ Playground Link

Not necessary.

πŸ’» Code

I work with a monorepo structure and some packages are installed in more than one folder. I don't want to skipLibCheck, because I need my own src/*.d.ts files to be checked. But at the same time, if I allow all node_modules to be checked on the tsc call, I'll get many conflicts, because a lot of library types will be declared in more than one place. So, this is what I always do:

tsconfig.json

// ...
"exclude": [
    "node_modules",
    "server/node_modules",
    "server-jobs/node_modules",    // THIS DOES NOT WORK
    "server_jobs/node_modules",    // THIS WORKS
    "public"
  ]

πŸ™ Actual behavior

When I added the server-jobs/node_modules folder, I started getting conflict errors for packages inside server-jobs/node_modules, which made no sense, because they were supposed to be excluded.

I tried tweaking my code, and experimented with some different include/exclude patterns. Nothing seemed to work. Until I though it could be related to the folder name, because of the dash "-" character. Since the server folder wasn't triggering any errors.

Then I changed it to server_jobs, with an underscore "_" and everything went back to normal. No more conflict errors.

I didn't find anything in the documentation for it.

https://www.typescriptlang.org/tsconfig#exclude

Is this a known issue? Is it supposed to behave like that?

πŸ™‚ Expected behavior

I expected for the tsc to parse folder names with dashes "-" without any issues, or at least for it to give me a heads up with a warning telling me that that folder name is not allowed.

@minestarks
Copy link
Member

This is surprising. I don't think dashes are the problem here (folders with dashes in their name work fine on other projects). Perhaps the folder name had a different type of dash (e.g. β€”) copy-and-pasted from somewhere? Perhaps other files were referencing the files under server-jobs?

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Feb 22, 2021
@RyanCavanaugh
Copy link
Member

Agree with Mine, it's implausible that dashes are the problem here; react-router exists and we would immediately hear about it if that didn't work. A more complete sample that reproduces the problem is needed.

@cbdeveloper
Copy link
Author

cbdeveloper commented Feb 23, 2021

Hey everyone,

Thank you all for the feedback. Just found out that the errors are still happening with the name server_jobs. The reason that they were gone initially is because I was deleting its node_modules before renaming (to speed up the rename operation). Of course the errors would be gone in that case. So it has nothing to do with the dashes - in the folder names. Sorry for the confusion.

I'm still finding it weird, though. Why would Typescript care for conflicts inside node_modules folders when they are being excluded? I can't use skipLibCheck because my project types are in some src/*.d.ts files that I do want to be checked. AFAIK, it's not possible to skipLibCheck just for node_modules, or is it?

This is now off-topic, but would be happy to hear your thoughts.

I'll close the issue since it's not about folder names at all.

This is my full tsconfig.json

// REFERENCE
// https://www.typescriptlang.org/tsconfig

{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": ".",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "module": "CommonJS",
    "moduleResolution": "Node",
    "noEmit": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "resolveJsonModule": true,
    // "skipLibCheck": true,
    "strictNullChecks": true,
    "target": "ESNext",
    "paths": {
      "@app/*":    ["./app/*"],
      "@common/*": ["./common/*"]
    }
  },
  "ts-node": {
    "files": true     // Load files, include and exclude from tsconfig.json on startup
  },
  "include": [
    "app/**/*",
    "common/**/*",
    "server/src/**/*",
    "server_jobs/src/**/*",
    "scripts/**/*"
  ],
  "exclude": [
    "node_modules",
    "server/node_modules",
    "server/dist_app",
    "server/dist_common",
    "server/dist_service",
    "server/public",
    "server_jobs/node_modules",
    "server_jobs/dist_common",
    "server_jobs/dist_service",
    "public"
  ]
}

These are the errors I'm getting:

image

@cbdeveloper
Copy link
Author

After further research and debug, I found out that the errors were being caused by a version difference between the firebase-admin that was installed on the project root as a devDependency and the firebase-admin installed on the server_jobs folder as a dependency.

Since the server_jobs folder was the most recent one, it had a more recent version of that package. After updating all to the same version, the errors went away.

But I still find it weird that those errors were caught by tsc, given the fact that all node_modules were excluded.

@RyanCavanaugh
Copy link
Member

exclude is only a filter on include; it doesn't change whether files can get imported into your program, or how they behave once present.

See also #30511

@l-jonasiak
Copy link

@cbdeveloper It's been a while since this issue was last answered. Have you found a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

4 participants