vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.75k stars 6.33k forks source link

Typescript project linting (ESLint) fails when using vue-cli-service build in Node container #5191

Open Tallyrald opened 4 years ago

Tallyrald commented 4 years ago

Version

4.2.2

Environment info

See details ``` System: OS: Linux 4.19 Debian GNU/Linux 9 (stretch) 9 (stretch) CPU: (2) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz Binaries: Node: 13.8.0 - /usr/local/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.13.6 - /usr/local/bin/npm Browsers: Chrome: Not Found Firefox: Not Found npmPackages: @vue/cli-overlay: 4.2.2 @vue/cli-plugin-eslint: ^4.2.2 => 4.2.2 @vue/cli-plugin-pwa: ^4.2.2 => 4.2.2 @vue/cli-plugin-router: 4.2.2 @vue/cli-plugin-typescript: ^4.2.2 => 4.2.2 @vue/cli-plugin-unit-mocha: ^4.2.2 => 4.2.2 @vue/cli-plugin-vuex: 4.2.2 @vue/cli-service: ^4.2.2 => 4.2.2 @vue/cli-shared-utils: 4.2.2 @vue/component-compiler-utils: 3.1.1 @vue/eslint-config-standard: ^5.1.2 => 5.1.2 @vue/eslint-config-typescript: ^5.0.1 => 5.0.1 @vue/preload-webpack-plugin: 1.1.1 @vue/web-component-wrapper: 1.2.0 eslint-plugin-vue: ^6.2.0 => 6.2.0 typescript: ^3.7.5 => 3.7.5 vue: ^2.6.11 => 2.6.11 vue-class-component: ^7.2.3 => 7.2.3 vue-cli-plugin-vuetify: ^2.0.5 => 2.0.5 vue-eslint-parser: 7.0.0 vue-hot-reload-api: 2.3.4 vue-loader: 15.9.0 vue-property-decorator: ^8.4.0 => 8.4.0 vue-router: ^3.1.5 => 3.1.5 vue-style-loader: 4.1.2 vue-template-compiler: ^2.6.11 => 2.6.11 vue-template-es2015-compiler: 1.9.1 vuetify: ^2.2.12 => 2.2.12 vuetify-loader: ^1.4.3 => 1.4.3 vuex: ^3.1.2 => 3.1.2 vuex-map-fields: ^1.3.6 => 1.3.6 npmGlobalPackages: @vue/cli: 4.2.2 ```

Steps to reproduce

Running vue-cli-service build in a node:13.8.0 docker container results in the following type of error for every file in the project:

error  in /src/router.ts

Module Error (from /node_modules/thread-loader/dist/cjs.js):

/src/router.ts
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: rc/router.ts.
The file must be included in at least one of the projects provided

✖ 1 problem (1 error, 0 warnings)

 @ /src/main.ts 3:0-35 17:12-23
 @ multi ../src/main.ts

The same command on a Windows 10 1909 machine works flawlessly. Note how the project config line says rc instead of src in the path while the file location is correct 2 lines before it.

At first I thought that this was a typescript-eslint issue so I created a ticket there, but it turns out that may not be the case, because the error does not occur when running vue-cli-service lint

Debug info when running `vue-cli-service build` ``` 2020-02-17T14:00:08.353Z typescript-eslint:typescript-estree:createProjectProgram Creating project program for: /rc/App.vue 2020-02-17T14:00:08.354Z typescript-eslint:typescript-estree:createWatchProgram File did not belong to any existing programs, moving to create/update. /rc/App.vue ```
Debug info when running `vue-cli-service lint` ``` 2020-02-17T13:59:01.164Z typescript-eslint:typescript-estree:createProjectProgram Creating project program for: /src/App.vue 2020-02-17T13:59:01.206Z typescript-eslint:typescript-estree:createWatchProgram Found existing program for file. /src/App.vue ```

What is expected?

Build succeeds.

What is actually happening?

Build fails with linting errors.

tsconfig.json ```json { "compilerOptions": { "target": "es2020", "module": "esnext", "strict": true, "jsx": "preserve", "importHelpers": true, "moduleResolution": "node", "experimentalDecorators": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", "types": [ "webpack-env", "mocha", "chai", "vuetify" ], "paths": { "@/*": [ "src/*" ], "components/*": [ "src/components/*" ] }, "lib": [ "esnext", "dom", "dom.iterable", "scripthost" ] }, "include": [ "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx" ], "exclude": [ "node_modules" ] } ```
tsconfig.eslint.json ```json { "extends": "./tsconfig.json", "include": [ ".eslintrc.js", "vue.config.js", "postcss.config.js" ], "compilerOptions": { "allowJs": true, "checkJs": true, "noEmit": true } } ```
.eslintrc.js ```js module.exports = { "env": { "browser": true, "es6": true, "node": true }, "extends": [ "plugin:vue/recommended", "@vue/typescript" ], "parser": "vue-eslint-parser", "parserOptions": { "extraFileExtensions": [".vue"], "parser": "@typescript-eslint/parser", "project": ['./tsconfig.json', './tsconfig.eslint.json'], "sourceType": "module", "tsconfigRootDir": __dirname, }, "plugins": [ "@typescript-eslint", "jsdoc", "prefer-arrow", "vue" ], "rules": { "@typescript-eslint/await-thenable": "warn", "@typescript-eslint/class-name-casing": "warn", "@typescript-eslint/consistent-type-definitions": "warn", "@typescript-eslint/interface-name-prefix": ["warn", { "prefixWithI": "always" }], "@typescript-eslint/member-delimiter-style": [ "warn", { "multiline": { "delimiter": "semi", "requireLast": true }, "singleline": { "delimiter": "semi", "requireLast": false } } ], "@typescript-eslint/member-ordering": "warn", "@typescript-eslint/no-empty-function": "warn", "@typescript-eslint/no-empty-interface": "warn", "@typescript-eslint/no-magic-numbers": [ "warn", { "ignore": [-1, 0, 1], "ignoreEnums": true, } ], "@typescript-eslint/no-var-requires": "warn", "@typescript-eslint/prefer-namespace-keyword": "warn", "@typescript-eslint/semi": [ "warn", "always" ], "@typescript-eslint/type-annotation-spacing": "warn", "arrow-body-style": "warn", "arrow-parens": [ "warn", "as-needed" ], "camelcase": "warn", "comma-dangle": [ "warn", "always-multiline" ], "complexity": "warn", "curly": [ "warn", "multi-line" ], "default-case": "warn", "eol-last": "warn", "eqeqeq": [ "warn", "smart" ], "guard-for-in": "warn", "id-blacklist": "warn", "id-match": "warn", "indent": ["error", "tab", {"SwitchCase": 1}], "jsdoc/check-alignment": 1, "jsdoc/check-param-names": 1, "jsdoc/check-tag-names": 1, "jsdoc/check-types": 1, "jsdoc/implements-on-classes": 1, "jsdoc/no-undefined-types": 1, "jsdoc/require-description": 1, "jsdoc/require-jsdoc": 1, "jsdoc/require-param": 1, "jsdoc/require-param-description": 1, "jsdoc/require-param-name": 1, "jsdoc/valid-types": 1, "max-classes-per-file": [ "warn", 1 ], "new-parens": "warn", "no-debugger": "warn", "no-empty": [ "warn", { "allowEmptyCatch": true } ], "no-eval": "warn", "no-irregular-whitespace": "warn", "no-magic-numbers": "off", "no-return-await": "warn", "no-throw-literal": "warn", "no-trailing-spaces": "warn", "no-underscore-dangle": "warn", "padding-line-between-statements": [ "warn", { "blankLine": "always", "next": "return", "prev": "*" } ], "prefer-arrow/prefer-arrow-functions": "warn", "quotes": ["error", "single", { "allowTemplateLiterals": true }], "sort-keys": "warn", "space-before-function-paren": [ "warn", "never" ], "spaced-comment": "warn", "vue/html-indent": ["warn", "tab"], "vue/html-self-closing": ["warn", { "html": { "component": "never", "normal": "never", "void": "never" }, "math": "never", "svg": "never" } ], "yoda": "warn", } }; ```
haoqunjiang commented 4 years ago

Thanks for submitting this issue! Due to our limited time, we ask you to include a reproduction link to a minimal full reproduction of your problem (for example in a GitHub repository) so we can find what is causing the issue. Thank you for your understanding!

Tallyrald commented 4 years ago

Thank you for getting back to me. I've been meaning to create such a repo, but couldn't get around to do it until now. Here it is:

https://github.com/Tallyrald/vue-cli-issue-5191

Please see the readme for info on how it was created and how to reproduce my issue. Thank you for your time!

tgeorgiev commented 4 years ago

Strange, I was hitting the same issue. In my case I have rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off' } in my .eslintrc.js and some file was doing "console.log". Then locally vue-cli-service build was completing just fine, while in a container it was properly failing. What I noticed was that locally I had node 10, where on the container it was node 12. After I upgraded locally to 12, the error started to appear.

JoelFeiner commented 1 year ago

I'm having the same issue. Even specifying the full path to the tsconfig file in .eslintrc.js I still get the error. Has anyone had any luck fixing this one?