I created a new NestJS project which is a very popular NodeJS framework. But I have this error (see title) on my IDE (PhpStorm 2020.2-Beta) and ESLint doesn't work at all.
I've used the NestJS CLI :
nest new nestjs-micro
I don't seem to be the only one with this problem, so it would be nice to find the cause of this problem and fix it once and for all.
I already have an open issue but I haven't had an answer, this is really very problematic.
If anyone has an idea on how to fix the problem and keeping an ESLint / Prettier integration with PhpStorm, thanks.
Repro
// .eslintrc.js
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
node: true,
jest: true,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
}
}
Versions
Typescript: 3.7.4
Node: 14.3.0
ESLint: 7.1.0
@typescript-eslint/parser: 3.0.2
Yarn: 1.22.4
I figured it out.
The error occurs when Typescript does not have a file to include for compilation.
The simplest solution is to create a tsconfig.build.json file for example and specify the following parameters in it :
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "dist/**/*spec.ts"],
"include": ["src/**/*", ".eslintrc.js"]
}
The above example is adapted for NestJS but should work for other projects.
The most surprising thing is that it's only an error that shows up on PHPStorm, the build, it works fine.