admin管理员组

文章数量:1123712

Steps to reproduce -

Create react redux typescript project using official command:

  • npx degit reduxjs/redux-templates/packages/vite-template-redux my-app

Add eslint using below command

  • npm i eslint
  • npx eslint --init

It generates eslint.config.mjs file with below contents:

import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";

/** @type {import('eslint').Linter.Config[]} */
export default [
  { files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
  { languageOptions: { globals: globals.browser } },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  pluginReact.configs.flat.recommended,
  { settings: { react: { version: "detect" } } },
];

tsconfig.json is also default:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.14.0",
    "@emotion/styled": "^11.14.0",
    "@fontsource/roboto": "^5.1.1",
    "@mui/icons-material": "^6.3.0",
    "@mui/material": "^6.3.0",
    "@mui/x-data-grid": "^7.23.5",
    "@reduxjs/toolkit": "^1.8.1",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.0.1",
    "@testing-library/user-event": "^14.1.1",
    "@types/jest": "^27.4.1",
    "@types/node": "^17.0.25",
    "@types/react": "^18.0.6",
    "@types/react-dom": "^18.0.2",
    "axios": "^1.7.9",
    "eslint": "^9.17.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-import-resolver-typescript": "^3.7.0",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-prettier": "^5.2.1",
    "i18next": "23.6.0",
    "i18next-browser-languagedetector": "^8.0.2",
    "i18next-http-backend": "^3.0.1",
    "jose": "^5.9.6",
    "qs": "^6.13.1",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "react-i18next": "^15.4.0",
    "react-redux": "^8.0.1",
    "react-router": "^7.1.1",
    "react-scripts": "5.0.1",
    "serve": "^14.2.4",
    "typescript": "^4.6.0",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
    "lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"",
    "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,md}\" --config ./.prettierrc.json",
    "serve": "npm run build && serve -s build"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@eslint/js": "^9.17.0",
    "eslint-plugin-react": "^7.37.3",
    "globals": "^15.14.0",
    "prettier": "^3.4.2",
    "typescript-eslint": "^8.19.0"
  }
}

Write function with any in it, it should give error - Unexpected any. Specify a different type.

Then disable it using comment:

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const myFunction = <P, Q>(error: any) => {}

Try running build and it gives error:

Failed to compile.

[eslint] 
src/utils.ts
  Line 3:1:  Definition for rule '@typescript-eslint/no-explicit-any' was not found  @typescript-eslint/no-explicit-any

Search for the keywords to learn more about each error.


error Command failed with exit code 1.

Linting is working fine, npm run start also works fine until I run build, but after build this error shows up in run and build both.

Steps to reproduce -

Create react redux typescript project using official command:

  • npx degit reduxjs/redux-templates/packages/vite-template-redux my-app

Add eslint using below command

  • npm i eslint
  • npx eslint --init

It generates eslint.config.mjs file with below contents:

import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";

/** @type {import('eslint').Linter.Config[]} */
export default [
  { files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
  { languageOptions: { globals: globals.browser } },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  pluginReact.configs.flat.recommended,
  { settings: { react: { version: "detect" } } },
];

tsconfig.json is also default:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

package.json:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.14.0",
    "@emotion/styled": "^11.14.0",
    "@fontsource/roboto": "^5.1.1",
    "@mui/icons-material": "^6.3.0",
    "@mui/material": "^6.3.0",
    "@mui/x-data-grid": "^7.23.5",
    "@reduxjs/toolkit": "^1.8.1",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "^13.0.1",
    "@testing-library/user-event": "^14.1.1",
    "@types/jest": "^27.4.1",
    "@types/node": "^17.0.25",
    "@types/react": "^18.0.6",
    "@types/react-dom": "^18.0.2",
    "axios": "^1.7.9",
    "eslint": "^9.17.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-import-resolver-typescript": "^3.7.0",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-prettier": "^5.2.1",
    "i18next": "23.6.0",
    "i18next-browser-languagedetector": "^8.0.2",
    "i18next-http-backend": "^3.0.1",
    "jose": "^5.9.6",
    "qs": "^6.13.1",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "react-i18next": "^15.4.0",
    "react-redux": "^8.0.1",
    "react-router": "^7.1.1",
    "react-scripts": "5.0.1",
    "serve": "^14.2.4",
    "typescript": "^4.6.0",
    "web-vitals": "^2.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
    "lint:fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"",
    "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,md}\" --config ./.prettierrc.json",
    "serve": "npm run build && serve -s build"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@eslint/js": "^9.17.0",
    "eslint-plugin-react": "^7.37.3",
    "globals": "^15.14.0",
    "prettier": "^3.4.2",
    "typescript-eslint": "^8.19.0"
  }
}

Write function with any in it, it should give error - Unexpected any. Specify a different type.

Then disable it using comment:

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const myFunction = <P, Q>(error: any) => {}

Try running build and it gives error:

Failed to compile.

[eslint] 
src/utils.ts
  Line 3:1:  Definition for rule '@typescript-eslint/no-explicit-any' was not found  @typescript-eslint/no-explicit-any

Search for the keywords to learn more about each error.


error Command failed with exit code 1.

Linting is working fine, npm run start also works fine until I run build, but after build this error shows up in run and build both.

Share Improve this question asked yesterday Girish AroraGirish Arora 92 bronze badges New contributor Girish Arora is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

I believe the generated eslint.config.mjs contains a mistake.

typescript-eslint docs say to configure tseslint like this:

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  eslint.configs.recommended,
  tseslint.configs.recommended,
);

https://typescript-eslint.io/getting-started/

But I don't see tseslint.config() called anywhere?

本文标签: reactjsBuild ErrorDefinition for rule 39typescripteslintnoexplicitany39 was not foundStack Overflow