programing

구문 분석 오류: 파일 '.../tsconfig'를 읽을 수 없습니다.json'.eslint

mailnote 2023. 4. 6. 21:53
반응형

구문 분석 오류: 파일 '.../tsconfig'를 읽을 수 없습니다.json'.eslint

「」Parsing error: Cannot read file '.../tsconfig.json'.eslint 됩니다..ts 파일src(「」를 포함)index.ts.

설정 방법을 모릅니다.이 문제는 빨간 선만 표시되며 파일은 빨간색이 된다.하지만 모든 게 잘 정리되고 잘 돌아가요.전체 노드 프로젝트는 Firebase CLI를 사용하여 생성되었습니다.

tsconfig.json 삭제:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

.eslintrc.js 삭제:

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",
      },
    },
  },
};

VScode를 재기동해 캐시를 클리어 해 봤지만 전혀 소용이 없었습니다.몇 가지 경로를 변경해야 할 것 같습니다만, 설정 파일을 변경하는 것은 서툴기 때문에 프로젝트 전체를 실수로 망가뜨리고 싶지 않습니다.

" " 입니다.project단위: s(표준))parserOptions는, 의 작업 는 현재 작업 디렉토리를 기준으로 해결됩니다.<고객명>을eslint에서 "Directory"를 tsconfig.json@typescript-eslint/parser로 지정합니다.

이 문제를 해결하려면__dirname는 프로젝트 을 '파서'에 .eslintrc.js:

module.exports = {
  // ...
  parserOptions: {
    project: "tsconfig.json",
    tsconfigRootDir: __dirname,
    sourceType: "module",
  },
  // ...
}

에 문제가 있으면

/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

질문을 보세요.

은 VSCode를 이었습니다..vscode합니다.settings.json★★★★

{
  "eslint.workingDirectories": [
    "src"
  ]
}

"src"eslint는 의 디렉토리여야 합니다.

eslintrc.json 파일을 다음 행으로 업데이트합니다.

"project": "PROJECT_NAME/tsconfig.json"

PROJECT_NAME은 프로젝트의 이름입니다(매크로가 아닙니다).

Angular 및 eslintrc.json을 사용하는 사용자의 경우 다음과 같이 프로젝트 노드에 별 2개를 추가합니다.

"overrides": [
    {
        "files": ["*.ts"],
        "parserOptions": {
            "project": ["**/tsconfig.json"],
        },

vscode를 사용하면 갑자기 이 오류가 나타나기 시작했습니다.vscoode를 재시작하면 문제가 해결되었습니다.

또 다른 접근법은 우연히 프로젝트보다 한 단계 위에 Workspace 폴더를 열었을 때(내 경우처럼) ACTUAL 프로젝트 폴더를 사용하여 새 Workspace를 시작하는 것입니다.이것으로 나의 에슬린트 오류가 해결되었다.

해서 가 풀었어요.@typescript-eslint/parser까지.

여기에 이미지 설명 입력

이를 수정한 것은 단순히 tsconfig.json이 포함된 프로젝트 디렉토리로 이동하여 파일을 찾을 수 있었다는 것입니다.

그렇지 않으면 "parserOptions" 내에서 .eslintrc.json "project" 어레이를 수정하여 현재 디렉토리 내에서 tsconfig.json의 위치를 찾을 수 있다는 @dheeraj9499의 답변이 마음에 들었습니다.따라서 다음과 같은 방법으로 올바른 디렉토리에서 tsconfig.json을 찾을 수 있었습니다.

"parserOptions": {
  "project": [
    "code/eMOS/Scripts/tsconfig.json",
    "code/eMOS/Scripts/tsconfig.spec.json"
  ],
 }

해석 오류: 'd:\test\test project\tsconfig.app.eslint.json' 파일을 읽을없습니다.eslint 프로젝트 폴더가 vs 코드로 열리는 방식으로 인해 여기서 직면한 주요 문제 중 하나입니다.

폴더 구조가 d:\test\test project라고 가정합니다.여기서 'test project'는 사용하고 있는 각도 프로젝트입니다.

테스트 폴더를 vs 코드로 열고 아래와 같이 테스트 프로젝트로 이동합니다.

D:\test>
D:\test>cd testproject
D:\test\testproject> 

이렇게 하면 열려 있는 메인 폴더용 파일과 하위 폴더용 파일 등 2개의 settings.json 파일이 생성되어 설정을 제대로 적용할 수 없습니다.

따라서 모든 종속성이 eslintrc.json 및 tsconfig.json 파일에 올바르게 언급되어 있으면 항상 vscode에서 직접 프로젝트 폴더를 열면 문제를 해결하는 데 도움이 됩니다.

Windows 10에서 WSL 2를 통해 타이프 스크립트 프로젝트를 진행할 때 Visual Studio Code에서 이 오류가 발생했습니다.

VS Code에 Remote - WSL 확장을 설치하여 수정되었습니다.

파일은 내 \wsl$\Ubuntu\home <user>\ 로케이션에서 호스트되었습니다.오류 메시지에 올바른 파일 위치가 지정되었으며 VS 코드가 파일을 열 수 있습니다.

루트 디렉토리와 파서 옵션을 사용한 위의 수정은 도움이 되지 않았습니다.

난 괜찮아

"parserOptions": {
  "project": ["<YourProjectName>/tsconfig.json"],
}

IntelliJ의 멀티 모듈프로젝트(예를 들어 프론트 엔드 모듈뿐만 아니라 여러 백엔드 서비스를 포함하는 폴더)에서 다음과 같은 오류 메시지가 표시될 경우 IntelliJ는 작업을 지시하지 못할 수 있습니다.

내 경우, 다음 오류가 위에 표시됩니다..ts- 파일:

이 문제를 해결하려면 "ESLint 설정"을 클릭합니다."를 선택한 후 "수동 ESLint 구성"을 선택합니다.

그런 다음 "Working directorys:"에서 프런트 엔드 모듈 루트 폴더에 대한 경로를 입력하고 "ESLint 패키지"에서 eslint에 대한 올바른 경로를 선택합니다(내 경우 - 에 있습니다).<frontend-module-root>/node_modules/eslint).

이렇게 하면 여전히 eslint가 작동하며 프로젝트 관련 설정을 변경할 필요가 없습니다(이미 CLI의 프런트 엔드 모듈 루트 폴더에서 작동합니다).

언급URL : https://stackoverflow.com/questions/64933543/parsing-error-cannot-read-file-tsconfig-json-eslint

반응형