typescript-eslint config: .eslintrc dosyası 'modül' tanımlı değil

Aug 19 2020

Typecript-eslint başlarken belgelerinde açıklandığı gibi yeni bir proje kuruyorum . Ancak .eslintrc.jsdosyamda bir hata alıyorum:

'modül' tanımlı değil. eslint (no-undef)

Ben kaldırmak Şimdi, eğer eslint:recommendedgelen extendsconfig, bu hata ortadan kalkar. Bununla birlikte, ESLint gibi tipik kurallar debuggerya da const iAmUnused = trueESLint tarafından algılanmaz, bu yüzden biraz köstebek vurma gibi geliyor.

ESLint dosyam projemin kökünde eslint:recommendedetkinleştirilmişken neden alınıyor ? Bu dosyayı benim klasörüme dahil etmek istemiyorum .eslintignoreçünkü eslintkomutumu çalıştırırken bu dosyanın zaten otomatik olarak yok sayıldığını söylüyor, ancak ,‍♂️ değil

ESLINTRC:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: '*/tsconfig.json',
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
  plugins: ['@typescript-eslint', 'jest', 'react', 'react-hooks'],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:jest/recommended',
    'plugin:prettier/recommended',
    'plugin:react/recommended',
    'plugin:react-hooks/recommended',
    'prettier',
    'prettier/@typescript-eslint',
  ],
  rules: {
    'no-unused-vars': 2,
  },
  env: {
    browser: true,
    es6: true,
    jest: true,
  },
  overrides: [
    {
      files: ['**/*.tsx'],
      rules: {
        'react/prop-types': 'off',
      },
    },
  ],
};

TSConfig:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "declaration": true,
    "declarationDir": "build",
    "jsx": "react",
    "lib": ["es6", "dom", "es2016", "es2017"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "resolveJsonModule": true,
    "rootDir": "./src",
    "rootDirs": ["./src"],
    "sourceMap": true,
    "strict": true,
    "target": "es5"
  },
  "include": ["./src"],
  "exclude": ["node_modules", "build", "dist", "src/**/*.stories.tsx", "src/**/*.test.tsx"]
}

Yanıtlar

6 PhilLucks Aug 21 2020 at 02:49

Görünüşe envgöre güncellenmesi gerekiyor:

env: {
    browser: true,
    es6: true,
    jest: true,
  },

dahil etmek node: trueiçin modulehata çözülecek.

BradZacher Aug 20 2020 at 12:51

https://eslint.org/docs/user-guide/configuring#specifying-environments

Projenizle ilgili ortamı / ortamları belirtmeniz gerekir.

Bu durumda, muhtemelen commonjsortamı eklemek istersiniz .

no-undefTypeScript tarafından zaten kapsanan bir kontrol olduğundan , kuralı kapatmayı düşünürdüm.