Closed OlegBrony closed 4 years ago
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
$ npm run lint
> hello-nest@0.0.1 lint /home/user/work/projects/hello-nest
> eslint "{src,apps,libs,test}/**/*.ts" --fix
but if I do something like that: project: '../tsconfig.json',
, then
$ npm run lint
> hello-nest@0.0.1 lint /home/user/work/projects/hello-nest
> eslint "{src,apps,libs,test}/**/*.ts" --fix
/home/user/work/projects/hello-nest/src/app.controller.spec.ts
0:0 error Parsing error: Cannot read file '/home/user/work/projects/tsconfig.json'
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
$ nest new nest-lint-problem -p yarn
Once the installation finished I moved into the new project's directory
$ cd nest-lint-problem
And then I ran the linter
$ yarn lint
eslint "{src,apps,libs,test}/**/*.ts" --fix
Done in 13.18s.
Just to be sure, I then ran eslint directly
yarn eslint --fix
~/nest-lint-problem/node_modules/.bin/eslint --fix
Done in 3.33s.
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
ornpm 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
ornpm 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 1) changing name from '.eslintrc.js' to '.eslintrc'. 2) making json from object (and fix all json syntax errors).
Adding "createDefaultProgram": true
to the tsconfig, after doing https://github.com/nestjs/nest/issues/4900#issuecomment-669743374 fixed it for me.
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module",
"createDefaultProgram": true
},
...
In my opinion, NestJS creates an erroneous configuration.
The file .eslintrc.js
shoud look like this:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'], // !!! new and important part !!!
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
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.
See also https://github.com/typescript-eslint/typescript-eslint/issues/967#issuecomment-530907956.
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.
"createDefaultProgram": true
worked, don't know why @@
Here is the fix
https://github.com/nestjs/nest/issues/4900#issuecomment-669743374
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
.eslintrc.js
I didn't change anything actually.
Environment
is it reproduced or is it just me?