Skip to content

Parsing error: File 'tsconfig.json' not found - if project does not contain tsconfig.json in workspace root #722

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

Closed
joepio opened this issue Jul 26, 2019 · 11 comments
Labels
info-needed Issue requires more information from poster

Comments

@joepio
Copy link

joepio commented Jul 26, 2019

I have a project (repo link) that has two separate tsconfig files in non-root folders. When I open this project in VScode, the linter gives this error in every TS file:

Parsing error: File '/project-root/tsconfig.json' not found.

That path indeed does not link to an existing file, since it should look in a specific subdirectory of project-root .

Whenever I open one of the subfolders, the error goes away and the plugin functions as expected.

Possibly related to #691

@joepio joepio changed the title Parsing error: File 'tsconfig.json' not found - if project does not contain tsconfig.json in root Parsing error: File 'tsconfig.json' not found - if project does not contain tsconfig.json in workspace root Jul 26, 2019
@TylerR909
Copy link

I also just ran in to this in a yarn workspace.

/project
|-- tsconfig.json <-- ESLint resolves to, but says doesn't exist
|-- packages/
|    |-- first/
|      |-- tsconfig.json <-- ESLint pointing to this, extends base config
|      |-- .eslintrc.js
|    |-- second/
|      |-- tsconfig.json

Trying to plug in ESLint in first/ right now. The package tsconfig.jsons both extend the root tsconfig.json. The .eslintrc.js file has this set...

  parserOptions: {
    project: './tsconfig.json',
  },

But it looks like the VSCode plugin is resolving that to project/tsconfig.json according to the error. If I set project: './packages/first/tsconfig.json then VSCode starts reporting all the errors but the command line is now reporting project/packages/first/packages/first/tsconfig.json is an error (shocker, I know).

Interesting note: The tsconfig.json that it's reporting isn't there... totally is. VSCode Tooltip on any file within packages/first/*:

Parsing error: File '/Users/{me}/Projects/{project-root}/tsconfig.json' not found. eslint

I'm going package by package to start, but planning on hoisting stuff to the root of the project and extending eslintrc files from a base. The plan right now is for every packages' eslintrc to point to its tsconfig.json project. May jump the gun on those plans a bit to see if it starts working with a root-level eslintrc.

@cyberixae
Copy link

I was able to fix the issue in my case by removing parserOptions entirely. I realise this may not work for everyone but for me it seemed fine.

@TylerR909
Copy link

For me the error resolved when I got started on integrating ESLint into a 2nd package. At that point, yarn workspace hoisting took over and pulled ESLint up to the root node_modules, VSCode ESLint Plugin could find the executable, and it started respecting nested .eslintrc files.

@TylerR909
Copy link

Sorta broke again. Yarn Workspaces stopped hoisting eslint-plugin-prettier even though it's used in two packages. packages/server and packages/client both use it and extend their common configs from the root of the project. The VSCode plugin is seeing eslint-plugin-prettier in the root config then instead of resolving it from packages/*/.eslintrc.js where it's used (and root=true for what it's worth), by searching packages/*/node_modules/eslint-plugin-prettier, the plugin is only searching /node_modules/eslint-plugin-prettier and since it's no longer being hoisted it's failing.

Over at the Yarn repo, since this has turned into a crapshow, I just did a cp -r packages/server/node_modules/eslint-plugin-prettier ./node_modules to effectively manually hoist it and immediately the VSCode ESLint plugin started working and reporting all my warnings and errors.

But that'll stop working the second I yarn install again, and it won't work for the rest of my team unless they do that too.

@ErikHumphrey
Copy link

Also experiencing the same issue because our project has no tsconfig.json in the root directory. Is it possible to specify a custom path?

@ErikHumphrey
Copy link

Possibly can't be fixed until typescript-eslint/typescript-eslint#251 is resolved (from #605)

@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2019

I am pretty sure that this is unrelated to the extension itself.

@joepio what happens if you validate files in the front / server folder in a terminal using eslint command. Will that work?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Aug 8, 2019
@joepio
Copy link
Author

joepio commented Aug 8, 2019

@joepio what happens if you validate files in the front / server folder in a terminal using eslint command. Will that work?

Running eslint in the /front subdirectory works just fine.

eslint --ext .js,.jsx,.ts,.tsx ./src

@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2019

@joepio I mean running it in the workspace folder. Something like

eslint --ext .js,.jsx,.ts,.tsx ./front/src

Have you tried to add the following configuration to tell eslint what your working directories are:

  "eslint.workingDirectories": [
    { "directory": "front", "changeProcessCWD": true },
    { "directory": "server", "changeProcessCWD": true }
  ]

@joepio
Copy link
Author

joepio commented Aug 8, 2019

@joepio I mean running it in the workspace folder. Something like

eslint --ext .js,.jsx,.ts,.tsx ./front/src

Does not seem to work: ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin"., which makes sense, since there is no node_modules folder with the plugin in that dir.

Have you tried to add the following configuration to tell eslint what your working directories are:

  "eslint.workingDirectories": [
    { "directory": "front", "changeProcessCWD": true },
    { "directory": "server", "changeProcessCWD": true }
  ]

This works! Nice, thanks!

@hasezoey hasezoey mentioned this issue Aug 8, 2019
@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2019

Closing the issue then.

@dbaeumer dbaeumer closed this as completed Aug 8, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants