The error Parsing error: Cannot read file '.../tsconfig.json'.eslint
shows in all .ts
files in the src
folder including index.ts
.
I have no idea how to set up configs. The issue just shows a red line and makes the file red. However, everything compiles and run fine. The entire Node project was created using the firebase CLI.
tsconfig.json
file:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
.eslintrc.js
file:
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
},
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "warn",
"comma-dangle": "warn",
"constructor-super": "error",
eqeqeq: ["warn", "always"],
"import/no-deprecated": "warn",
"import/no-extraneous-dependencies": "error",
"import/no-unassigned-import": "warn",
"no-cond-assign": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": [
"error",
{
allowEmptyCatch: true,
},
],
"no-invalid-this": "error",
"no-new-wrappers": "error",
"no-param-reassign": "error",
"no-redeclare": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
hoist: "all",
},
],
"no-throw-literal": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-var": "warn",
"no-void": "error",
"prefer-const": "warn",
},
settings: {
jsdoc: {
tagNamePreference: {
returns: "return",
},
},
},
};
I had tried restarting VScode, clearing the cache, and all to no avail. I am guessing I need to change some of the paths but I am not very good at changing the config files so I don’t want to accidentally break the entire project.
Содержание
- Eslint parsing error cannot read file
- Parsing Error: Cannot read file ‘tsconfig.json’ #
- «Cannot read file» with lowercase name in mac #2213
- Comments
- eslint: Parsing error: «parserOptions.project» has been set for @typescript-eslint/parser. #4900
- Comments
- Bug Report
- Current behavior
- Input Code
- Environment
- This comment has been minimized.
- Footer
- Ошибка анализа: не удается прочитать файл ‘… / tsconfig.json’.eslint
Eslint parsing error cannot read file
Reading time В· 3 min
Parsing Error: Cannot read file ‘tsconfig.json’ #
To solve the error «Parsing Error: Cannot read file ‘tsconfig.json’», update your .eslintrc.js file to set the tsconfigRootDir option to __dirname to force eslint to resolve your project configuration relative to the folder where .eslintrc.js is located.
Open your .eslintrc.js file and add or update your parserOptions object to look like:
By setting the parserOptions object we tell ESLint which JavaScript language options we want to support.
The sourceType option is set to module to indicate that we want to support ES6 Modules.
Once you’ve updated your parserOptions object, you might get an error:
If you got the «parserOptions.project» has been set for @typescript-eslint/parser error, create a tsconfig.eslint.json file in your root directory, right next to your tsconfig.json file.
Make sure to add all of the directories you want to lint in the include array.
Now open your .eslintrc.js file and update the project property to point to the eslint-specific tsconfig file.
Your error should be resolved, if it isn’t try restarting your IDE.
This is needed because adding the parserOptions.project option to a TypeScript project causes ESLint to throw an error if we try to lint files that aren’t included in our TypeScript project.
In short, add all the files that you want to lint, but are not included in your tsconfig.json file to the include array in your tsconfig.eslint.json file. These will most likely be config files that are located in your root directory.
Alternatively, you can add any of the files in which you see the error to your .eslintignore file if you don’t want to lint them.
If the error «Parsing Error: Cannot read file ‘tsconfig.json’» is still not resolved and you use the VSCode IDE, create a .vscode folder in the root directory of your project.
Add a settings.json file in the .vscode directory and paste the following contents.
This file assumes that you want to lint an src directory.
If your project has 2 directories that you want to lint, e.g. frontend and backend , update the workingDirectories array to look like this:
The setting instructs ESLint how to resolve config files ( .eslintrc.js and .eslintignore ) relative to our working directory.
For example, if your project is in a user/typescript/ directory and you open your code editor in the user/ directory, you might get the error.
Instead, try to navigate to the user/typescript/ directory first and then open your code editor.
Источник
«Cannot read file» with lowercase name in mac #2213
I’m using eslint on mac. I have a large React project in js, and I’m trying to start using ts. I’ve changed only one file to ts (in my shared/utils/ folder) and tested eslint.
Expected to pass, but got this error:
What’s weird is that /Users/* folder became /users/* folder — so I assume this is what caused the file to be not found.
This is what running with —debug showed me:
Most of the eslint config ( .eslintrc.js ) is this:
Versions
package | version |
---|---|
@typescript-eslint/parser | 3.2.0 |
TypeScript | 3.9.5 |
ESLint | 7.2.0 |
node | 12.6.2 |
npm | 6.14.4 |
The text was updated successfully, but these errors were encountered:
macos is case INsensitive for filenames, which is why typescritpt lowercases the paths.
I’m not able to repro this — could you please provide a repro repo to help investigate?
Solved it thanks to the idea to create repro repo. When I succeeded recreating it I discovered the problem.
It was in the eslintrc portion that I omitted because it was related to internal code.
I had this code, using an object called appsMapping that has the names of all apps in our repo:
What I haven’t noticed is that we did there join to a string, and then spread operator on the string. The path was invalid.
Источник
eslint: Parsing error: «parserOptions.project» has been set for @typescript-eslint/parser. #4900
Bug Report
I installed nest and start new project. and there is a problem with eslint: in .eslint.js I got error
eslint in code also not working, and command npm run lint doesn’t find any problems.
Current behavior
Input Code
I didn’t change anything actually.
Environment
is it reproduced or is it just me?
The text was updated successfully, but these errors were encountered:
I can’t reproduce your issue.
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
I can’t reproduce your issue.
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
ok, but what should I looking for? looks like I don’t get relevant result when I google Parsing error: «parserOptions.project» has been set for @typescript-eslint/parser.
edit: well, I did some researches. first, eslint is working. I can’t understand where is the bug. web storm says that:
but
but if I do something like that: project: ‘../tsconfig.json’, , then
so, eslint really trying to find the tsconfig file, and he can found it, but ide is showing error. how to fix that? or it doesn’t matter? lint works anyway.
@OlegBrony, looks like this happened because webstorm automatically tries to apply eslint to .eslintrc.js file and parse it with typescript config (which is not working with js files). You can safely ignore it.
I believe this issue should be a bug.. I am having the same error. The script lint runs but doesn’t fix or complain about any of the many linting errors I left in the code.
@BrenoGO can you provide a minimum reproduction?
Just run «nest new my-project» («@nestjs/cli»: «^7.0.0»,). The .eslintrc will show the error of this issue’s title.
I ran the eslint —init, now I will configure it. I thought it would start already configured.
I am using the nest 7.4.1.
Using the git clone https://github.com/nestjs/typescript-starter.git, it’s the same..
Does anyone does these procedures and the eslint works fine?! Could be something with my VSCode?
In other projects I always use it configuring from beginning with eslint —init and is working fine..
@BrenoGO using the latest version of the Nest CLI I created a new project
Once the installation finished I moved into the new project’s directory
And then I ran the linter
Just to be sure, I then ran eslint directly
Not sure what you’re facing, but the configuration setup is fine in terms of running the lint command. It sounds like the problem is with the IDE, as in eslint trying to lint the .eslintrc.js file. As that doesn’t really happen from the lint commands, I don’t really see it being an issue. If you want to fix it though, you can create an .eslintignore file and add all .js files or specific ones, just like you would for a .gitignore
The problem is when we go to a file and leave some code out of pattern, the eslint does not report any errors..
I thought this should be not happening as expected because of the error in the .eslintrc below:
Solved by replacing filename from .eslintrc.js to .eslintrc and removing module.exports etc.
Doing that the error in .eslintrc will be gone. But still some basic rules like «semi», «comma-dangle» and «quotes» are not being reported by the eslint. It seems like we have to configure it all by ourselves..
Doing that the error in .eslintrc will be gone. But still some basic rules like «semi», «comma-dangle» and «quotes» are not being reported by the eslint. I seems like we have to configure it all by ourselves..
You should install this dependencies
yarn add eslint-config-prettier eslint-plugin-prettier —dev or npm install eslint-config-prettier eslint-plugin-prettier —save-dev
And replace extends object in .eslintrc by this
«extends»: [
«plugin:@typescript-eslint/eslint-recommended»,
«plugin:@typescript-eslint/recommended»,
«prettier/@typescript-eslint»,
«plugin:prettier/recommended»
]
After VsCode reload should work
Doing that the error in .eslintrc will be gone. But still some basic rules like «semi», «comma-dangle» and «quotes» are not being reported by the eslint. I seems like we have to configure it all by ourselves..
You should install this dependencies
yarn add eslint-config-prettier eslint-plugin-prettier —dev or npm install eslint-config-prettier eslint-plugin-prettier —save-dev
And replace extends object in .eslintrc by this
«extends»: [
«plugin:@typescript-eslint/eslint-recommended»,
«plugin:@typescript-eslint/recommended»,
«prettier/@typescript-eslint»,
«plugin:prettier/recommended»
]
After VsCode reload should work
There we go! thanks
Doing that the error in .eslintrc will be gone. But still some basic rules like «semi», «comma-dangle» and «quotes» are not being reported by the eslint. I seems like we have to configure it all by ourselves..
You should install this dependencies
yarn add eslint-config-prettier eslint-plugin-prettier —dev or npm install eslint-config-prettier eslint-plugin-prettier —save-dev
And replace extends object in .eslintrc by this
«extends»: [
«plugin:@typescript-eslint/eslint-recommended»,
«plugin:@typescript-eslint/recommended»,
«prettier/@typescript-eslint»,
«plugin:prettier/recommended»
]
After VsCode reload should work
Does not worked for me
@lucasluca , did you also did that?
Solved by replacing filename from .eslintrc.js to .eslintrc and removing module.exports etc.
what did not work for you?
I did exactly the same thing. Added the packages and extended what was recommended. I still have the same issue.
I had to change the extension of the .eslintrc.js to ts . Then it was resolved.
SO. all the fix was about
- changing name from ‘.eslintrc.js’ to ‘.eslintrc’.
- making json from object (and fix all json syntax errors).
Adding «createDefaultProgram»: true to the tsconfig, after doing #4900 (comment) fixed it for me.
In my opinion, NestJS creates an erroneous configuration.
The file .eslintrc.js shoud look like this:
By adding ignorePatterns: [‘.eslintrc.js’] eslint is told to ignore the .eslintrc.js file itself.
Otherwise it results in an error, because eslint tries to lint the .eslintrc.js file, even though it is not included in the tsconfig.json configuration.
The lint command that Nest provides in the package.json works fine, and I can’t reproduce this on VSCode unless I open up the .eslintrc.js file. However, I do see where this is coming from, so if you’d like to create a PR to the typescript-starter to add that line in, please feel free to do so. I’ll double check if any other locations would need it as well.
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Ошибка анализа: не удается прочитать файл ‘… / tsconfig.json’.eslint
Ошибка Parsing error: Cannot read file ‘. /tsconfig.json’.eslint отображается во всех .ts файлах в src папке, включая index.ts .
Понятия не имею, как настраивать конфиги. Проблема просто показывает красную линию и делает файл красным. Однако все компилируется и работает нормально. Весь проект Node был создан с использованием интерфейса командной строки firebase.
Я попытался перезапустить VScode, очистить кеш, и все безрезультатно. Я предполагаю, что мне нужно изменить некоторые пути, но я не очень хорошо умею изменять файлы конфигурации, поэтому я не хочу случайно сломать весь проект.
По умолчанию project s (in parserOptions ) разрешаются относительно текущего рабочего каталога. Если вы запустите eslint в другом рабочем каталоге, чем содержащая его папка tsconfig.json , @ typescript-eslint / parser не сможет найти файл.
Чтобы исправить это, вы можете установить tsconfigRootDir значение __dirname , которое заставит парсер разрешить конфигурацию проекта относительно .eslintrc.js :
Подход, специфичный для VSCode, который сработал для меня, заключался в создании .vscode папки в корневом каталоге проекта и добавлении следующего свойства в settings.json файл внутри нее:
Это «src» может быть любой каталог, который должен находиться в области видимости eslint.
обновите файл eslintrc.json следующей строкой:
Ошибка анализа: не удается прочитать файл ‘d: test testproject tsconfig.app.eslint.json’.eslint Одна из основных проблем, с которыми я столкнулся здесь, из-за способа открытия папки проекта в коде vs.
Предположим, что структура папок — d: test testproject, где testproject — это проект angular, который вы используете.
если вы открываете тестовую папку в vs code, переходите к testproject, как показано ниже
Источник
Issue
The error Parsing error: Cannot read file '.../tsconfig.json'.eslint
shows in all .ts
files in the src
folder including index.ts
.
I have no idea how to set up configs. The issue just shows a red line and makes the file red. However, everything compiles and run fine. The entire Node project was created using the firebase CLI.
tsconfig.json
file:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
.eslintrc.js
file:
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
},
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "warn",
"comma-dangle": "warn",
"constructor-super": "error",
eqeqeq: ["warn", "always"],
"import/no-deprecated": "warn",
"import/no-extraneous-dependencies": "error",
"import/no-unassigned-import": "warn",
"no-cond-assign": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": [
"error",
{
allowEmptyCatch: true,
},
],
"no-invalid-this": "error",
"no-new-wrappers": "error",
"no-param-reassign": "error",
"no-redeclare": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
hoist: "all",
},
],
"no-throw-literal": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-var": "warn",
"no-void": "error",
"prefer-const": "warn",
},
settings: {
jsdoc: {
tagNamePreference: {
returns: "return",
},
},
},
};
I had tried restarting VScode, clearing the cache, and all to no avail. I am guessing I need to change some of the paths but I am not very good at changing the config files so I don’t want to accidentally break the entire project.
Solution
By default, the project
s (in parserOptions
) are resolved relative to the current working directory. If you run eslint
in a different working directory to the folder containing tsconfig.json
, @typescript-eslint/parser will not be able to locate the file.
To fix this, you can set tsconfigRootDir
to __dirname
, which would make the parser resolve the project configuration relative to .eslintrc.js
:
module.exports = {
// ...
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
sourceType: "module",
},
// ...
}
Answered By — cherryblossom
Issue
The error Parsing error: Cannot read file '.../tsconfig.json'.eslint
shows in all .ts
files in the src
folder including index.ts
.
I have no idea how to set up configs. The issue just shows a red line and makes the file red. However, everything compiles and run fine. The entire Node project was created using the firebase CLI.
tsconfig.json
file:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
.eslintrc.js
file:
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module",
},
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "warn",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/unified-signatures": "warn",
"comma-dangle": "warn",
"constructor-super": "error",
eqeqeq: ["warn", "always"],
"import/no-deprecated": "warn",
"import/no-extraneous-dependencies": "error",
"import/no-unassigned-import": "warn",
"no-cond-assign": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-empty": [
"error",
{
allowEmptyCatch: true,
},
],
"no-invalid-this": "error",
"no-new-wrappers": "error",
"no-param-reassign": "error",
"no-redeclare": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
hoist: "all",
},
],
"no-throw-literal": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-var": "warn",
"no-void": "error",
"prefer-const": "warn",
},
settings: {
jsdoc: {
tagNamePreference: {
returns: "return",
},
},
},
};
I had tried restarting VScode, clearing the cache, and all to no avail. I am guessing I need to change some of the paths but I am not very good at changing the config files so I don’t want to accidentally break the entire project.
Solution
By default, the project
s (in parserOptions
) are resolved relative to the current working directory. If you run eslint
in a different working directory to the folder containing tsconfig.json
, @typescript-eslint/parser will not be able to locate the file.
To fix this, you can set tsconfigRootDir
to __dirname
, which would make the parser resolve the project configuration relative to .eslintrc.js
:
module.exports = {
// ...
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
sourceType: "module",
},
// ...
}
If you’re getting some trouble with
/path/to/.eslintrc.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: .eslintrc.js.
The file must be included in at least one of the projects provided
see this question.
Answered By – cherryblossom
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0