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

Parser is looking in the wrong place for the tsconfig file #2814

Closed
3 tasks done
Tbhesswebber opened this issue Nov 25, 2020 · 7 comments · Fixed by #2819
Closed
3 tasks done

Parser is looking in the wrong place for the tsconfig file #2814

Tbhesswebber opened this issue Nov 25, 2020 · 7 comments · Fixed by #2819
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@Tbhesswebber
Copy link

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

I apologize for the size of this repro - I am in a weird spot where I am using (Narwhal Extensions)[nx.dev] with nx-electron and somehow the whole shebang has managed to cause the parser to lose track of the base tsconfig in some circumstances.

To run linting on every piece of the project, you have to run nx run-many --target lint --all --parallel (the parallel flag just speeds it all up).

This is a super greenfield POC that just got started, so it's essentially empty, but I'd be happy to jump into a chat to better understand/explain the problem in order to file a better issue with whomever the real culprit is if it's not the parser.

# error message being received (file paths are condensed)
...galvanize/apps/g-ent-e2e/src/integration/app.spec.ts
  0:0  error  Parsing error: Cannot read file '.../galvanize/node_modules/tsconfig.base.json'

Running with typescript-eslint in debug mode hasn't seemed to provide any clarity.

Expected Result

I expected the parser to look at the root of the workspace for tsconfig.base.json

Actual Result

A number of files are causing parsing errors at line 0 column 0 because the parser is looking for ./node_modules/tsconfig.base.json rather than ./tsconfig.base.json. This does not happen with all of the files.

Additional Info

There are a couple hundred more lines of output from running DEBUG=typescript-eslint:* nx run-many --target lint --all --parallel, but none seem to be concerning.

typescript-eslint:typescript-estree:createProjectProgram Creating project program for: /Users/tannerhesswebber/Documents/code/galvanize/galvanize/apps/g-ent-desktop/src/environments/environment.prod.ts +330ms
  typescript-eslint:typescript-estree:createWatchProgram Found existing program for file. /users/tannerhesswebber/documents/code/galvanize/galvanize/apps/g-ent-desktop/src/environments/environment.prod.ts +330ms
  typescript-eslint:parser:parser Resolved libs from program: [ 'es2017', 'dom' ] +329ms

/Users/tannerhesswebber/Documents/code/galvanize/galvanize/apps/g-ent-desktop/src/environments/environment.ts
  0:0  error  Parsing error: Cannot read file '/users/tannerhesswebber/documents/code/galvanize/galvanize/node_modules/tsconfig.base.json'

Versions

package version
@typescript-eslint/parser 4.3.0
TypeScript 4.0.3
ESLint 7.10.0
node (system) 12.16.3
electron 7.1.0
@Tbhesswebber Tbhesswebber added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Nov 25, 2020
@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Nov 25, 2020
@Tbhesswebber
Copy link
Author

Thanks so much! Feel free to deprioritize this for the time being... it is a holiday week after all!

I pushed the changes recommended in those docs and still seem to have three locations where it isn't registering the update. It seems like these are changes that may need to be propagated over to nx, which I will definitely do once things are resolved.

Also, is this a place where following these directions for monorepos would be valuable? It feels like I'm right on the line to me.

@bradzacher
Copy link
Member

Our tooling essentially does this

fs.readFileSync(
  path.join(
    parserOptions.tsconfigRootDir ??  process.cwd(),
    parserOptions.project,
 ),
);

So if you are finding it's not finding the tsconfigs, then likely there's likely something else getting in the way.

I do notice that you haven't set parserOptions.tsconfigRootDir in the non-overridden, base config.

@Tbhesswebber
Copy link
Author

I updated the non-overridden base config and am still seeing the behavior. The fact that it's essentially doing a path.join makes me wonder what's going on under the hood in other places... somehow the parser is looking in node_modules for tsconfig.base.json 🤔

# this is the path of the file being parsed
/Users/.../galvanize/apps/g-ent-desktop/src/environments/environment.ts

# this is the path of the eslint config file
/Users/.../galvanize/apps/g-ent-desktop/.eslintrc.json

# this is the path of the config file it extends
/Users/.../galvanize/.eslintrc.js

# this is the path of the tslint file that reads
/Users/.../galvanize/tsconfig.base.json

# this is the path from the error about not being able to read the file
/Users/.../galvanize/node_modules/tsconfig.base.json'

@bradzacher bradzacher added bug Something isn't working and removed awaiting response Issues waiting for a reply from the OP or another party labels Nov 26, 2020
@bradzacher
Copy link
Member

bradzacher commented Nov 26, 2020

So I keep digging, but I can't figure out exactly what's happening - I can't figure out exactly where /users/.../typescript-eslint-debug-main/node_modules/tsconfig.base.json is coming from.
I think it's one of the nrwl module's tsconfigs referencing a project with a relative path like '../../../tsconfig.base.json', which is then being resolved to the root node_modules folder.

So why is a nrwl module tsconfig being included? This is a regression introduced in #2418. When I switched the codebase to globby, I didn't re-implement the default glob filter (which should be **/node_modules/**).

Which means that your globs are matching aaaallll of these tsconfigs:

parserOptions.project (excluding ignored) matched projects: Set {
  '/users/.../tsconfig.base.json',
  '/users/.../tools/tsconfig.tools.json',
  '/users/.../apps/g-ent/tsconfig.app.json',
  '/users/.../apps/g-ent/tsconfig.spec.json',
  '/users/.../apps/g-ent-desktop/tsconfig.app.json',
  '/users/.../apps/g-ent-desktop/tsconfig.spec.json',
  '/users/.../apps/g-ent-e2e/tsconfig.e2e.json',
  '/users/.../node_modules/microevent.ts/tsconfig.test.json',
  '/users/.../node_modules/worker-rpc/tsconfig.test.json',
  '/users/.../node_modules/@nrwl/cli/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/cli/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/cypress/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/cypress/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/jest/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/jest/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/linter/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/linter/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/react/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/react/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/tao/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/tao/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/web/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/web/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/workspace/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/workspace/tsconfig.spec.json',
  '/users/.../node_modules/@nrwl/cypress/src/schematics/cypress-project/files/tsconfig.e2e.json',
  '/users/.../node_modules/@nrwl/workspace/src/schematics/workspace/files/tsconfig.base.json',
  '/users/.../node_modules/nx-electron/src/schematics/application/files/app/tsconfig.app.json',
  '/users/.../node_modules/@nrwl/react/src/schematics/application/files/app/tsconfig.app.json',
  '/users/.../node_modules/@nrwl/react/src/schematics/library/files/lib/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/web/src/schematics/application/files/app/tsconfig.app.json',
  '/users/.../node_modules/@nrwl/workspace/src/schematics/init/files/tools/tsconfig.tools.json',
  '/users/.../node_modules/@nrwl/workspace/src/schematics/library/files/lib/tsconfig.lib.json',
  '/users/.../node_modules/@nrwl/workspace/src/schematics/workspace/files/tools/tsconfig.tools.json',
  '/users/.../node_modules/nx-electron/node_modules/@nrwl/jest/src/schematics/jest-project/files/tsconfig.spec.json',
  '/users/.../node_modules/nx-electron/node_modules/@nrwl/workspace/src/schematics/init/files/tools/tsconfig.tools.json',
  '/users/.../node_modules/nx-electron/node_modules/@nrwl/workspace/src/schematics/library/files/lib/tsconfig.lib.json',
  '/users/.../node_modules/nx-electron/node_modules/@nrwl/workspace/src/schematics/workspace/files/tools/tsconfig.tools.json'
}

So what's the fix?
Simply add projectFolderIgnoreList: ['**/node_modules/**'] to your parserOptions.
I'll fix this in the main module.

Also you can simplify your eslint config a bit (changes including the fix): Tbhesswebber/typescript-eslint-debug#1

@bradzacher bradzacher added package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed package: parser Issues related to @typescript-eslint/parser labels Nov 26, 2020
@Tbhesswebber
Copy link
Author

Thanks for digging into this and for updating my config! Did you discover any changes that I should be requesting within Narwhal Extensions in conjunction with the fix that you identified? I think that tsconfig.base.json is intentionally set up to be agnostic by Nx so that all of the various workspaces that they support don't run into issues, but I'm not 100% on that

Happy Thanksgiving!!

@bradzacher
Copy link
Member

no changes to narwhal.
I'll have a PR ready for this repo momentarily.

bradzacher added a commit that referenced this issue Nov 26, 2020
…olderIgnoreList` and deduplicate resolved projects

In #2418 I introduced a regression - I forgot to add in the default value for `projectFolderIgnoreList`.
This means that globs have been matching `node_modules` since the v4.0 release! Oops :(

This PR fixes that.
It also hoists the tsconfig path canonicalisation up so that we can deduplicate early.
Previously if you provided a config like `projects: ['./tsconfig.json', './**/tsconfig.json']`, then we would resolve this to `./tsconfig.json` and `tsconfig.json`, then later canonicalise them.
This meant we'd check that same tsconfig twice!
By hoisting the canonicalisation, we can deduplicate this early.

Fixes #2814
bradzacher added a commit that referenced this issue Nov 26, 2020
…olderIgnoreList` and deduplicate resolved projects (#2819)

In #2418 I introduced a regression - I forgot to add in the default value for `projectFolderIgnoreList`.
This means that globs have been matching `node_modules` since the v4.0 release! Oops :(

This PR fixes that.
It also hoists the tsconfig path canonicalisation up so that we can deduplicate early.
Previously if you provided a config like `projects: ['./tsconfig.json', './**/tsconfig.json']`, then we would resolve this to `./tsconfig.json` and `tsconfig.json`, then later canonicalise them.
This meant we'd check that same tsconfig twice!
By hoisting the canonicalisation, we can deduplicate this early.

Fixes #2814
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
2 participants