在我的 TypeScript 项目在 VSCode 中初始化后,使用 firebase 工具按照官方文档编写 Firebase Cloud Functions,文件的第一行index.ts
显示错误:
Parsing error: Cannot read file '\tsconfig.json' eslint [1,1]
并且.eslintrc.js
显示错误:
File is a CommonJS module; it may be converted to an ES6 module.ts(80001)
由于所有文件都是自动生成的,这些错误完全令人惊讶,我想摆脱它们。
作为记录,以下是安装的版本:
npm --version 8.1.3
tsc --version 4.4.4
node --version 17.0.1
firebase --version 9.22.0
Run Code Online (Sandbox Code Playgroud)
这些是我在 VSCode 的 powershell 中使用的命令以及一些信息/警告:
>npm install -g firebase-tools
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade …
Run Code Online (Sandbox Code Playgroud) 当克隆我的存储库并在 WSL2 上执行 npm install 时,我在 IDE 上针对项目中的所有 .ts 文件收到此 ESLint 错误:
ESLint:解析错误:无法读取文件
\\wsl$\ubuntu-20.04\home\project_directory\tsconfig.json
这是因为我parserOptions
在我的.eslintrc.json
文件中出现的。
我尝试解决这个问题:
__dirname
. 但这并不能解决我的问题。eslint
从我的项目的node_modules
. 似乎没有什么可以为我消除这个错误。eslint
没有显示任何问题。不知道为什么它在 WSL 上的工作效果不一样。任何帮助将不胜感激,因为我不确定下一步该做什么。
.eslintrc.json
{
"env": {
"browser": true,
"es2021": true,
"node": true,
"jest": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": …
Run Code Online (Sandbox Code Playgroud) ESLint 似乎无法解析“.eslintrc.js”文件。
重现步骤:我建立了一个新的“hello world”TypeScript 项目,如下所示:
# Make a new directory for our new project
mkdir test
# Go into the new directory
cd test
# Create a "package.json" file
npm init --yes
# Install TypeScript
npm install typescript --save-dev
# Install ESLint (the linter)
npm install eslint --save-dev
# Install the Airbnb ESLint config (the most popular linting config in the world)
npm install eslint-config-airbnb-typescript --save-dev
# The import plugin for ESLint is needed for the Airbnb config to …
Run Code Online (Sandbox Code Playgroud) 当我打开.vue
文件时,我的 IntelliJ IDEA 中出现以下错误:
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: XX\XX\CurrentFile.vue.
The file must be included in at least one of the projects provided.
Run Code Online (Sandbox Code Playgroud)
当然,如果你教我解决方案,我会很高兴,但首先我知道它意味着什么以及为什么会出现。
我怀疑这是某种错误或不准确的错误消息。实验上已知:
eslint
从控制台运行某个.vue
文件,eslint 将正确完成执行。所以看起来它不是 eslint 错误。我的 Eslint 配置(YAML):
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: XX\XX\CurrentFile.vue.
The file must be included in at least …
Run Code Online (Sandbox Code Playgroud)