无法构建和lint Nexts 13项目,no-unused-vars错误

ibrsph3r  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(96)

我无法构建Next.js 13项目,有许多错误,如:
错误:<SOME_NAME>已分配值但从未使用。无未用变量
我的设置与以前版本的Next.js和React(Vite)一起工作。我需要使用yarn lint自动删除未使用的导入,并使用yarn dev进行构建。如何配置设置来修复它?
下面是我的eslintrc.json

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "next/core-web-vitals"],
  "overrides": [],
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module",
    "project": ["./tsconfig.json"]
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "unused-imports"],
  "root": true,
  "rules": {
    "no-unused-vars": [
      "error",
      { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }
    ],
    "@typescript-eslint/no-unused-vars": "off",
    "unused-imports/no-unused-imports": "warn",
    "unused-imports/no-unused-vars": [
      "warn",
      {
        "vars": "all",
        "varsIgnorePattern": "^_",
        "args": "after-used",
        "argsIgnorePattern": "^_"
      }
    ]
  }
}

字符串

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [{ "name": "next" }],
    "paths": {"@/*": ["./*"]},
    "strict": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "npx eslint . --ext .ts,.tsx,.js,.jsx --fix",
    "prettier": "npx prettier --write ."
  },
  "dependencies": {
    "@emotion/react": "^11.11.0",
    "@emotion/styled": "^11.11.0",
    "@mui/material": "^5.13.2",
    "@mui/x-date-pickers": "^6.5.0",
    "@reduxjs/toolkit": "^1.9.5",
    "@types/node": "20.2.4",
    "@types/react": "18.2.7",
    "@types/react-dom": "18.2.4",
    "@wangeditor/editor": "^5.1.23",
    "@wangeditor/editor-for-react": "^1.0.6",
    "axios": "^1.4.0",
    "d3": "^7.8.4",
    "dayjs": "^1.11.7",
    "eslint": "^8.0.1",
    "eslint-config-next": "13.4.4",
    "framer-motion": "^10.12.16",
    "lodash": "^4.17.21",
    "next": "13.4.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-icons": "^4.8.0",
    "react-redux": "^8.0.5",
    "serialize-javascript": "^6.0.1",
    "socket.io-client": "^4.6.1",
    "typescript": "*",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@next/eslint-plugin-next": "^13.4.4",
    "@types/lodash": "^4.14.195",
    "@types/uuid": "^9.0.1",
    "@typescript-eslint/eslint-plugin": "^5.43.0",
    "@typescript-eslint/parser": "^5.59.7",
    "eslint-config-prettier": "^8.8.0",
    "eslint-config-standard-with-typescript": "^34.0.1",
    "eslint-plugin-import": "^2.25.2",
    "eslint-plugin-n": "^15.0.0",
    "eslint-plugin-promise": "^6.0.0",
    "eslint-plugin-react": "^7.32.2",
    "eslint-plugin-unused-imports": "^2.0.0",
    "prettier": "^2.8.8",
    "redux-devtools-extension": "^2.13.9",
    "sass": "^1.63.6"
  }
}

  • 谢谢-谢谢
t1qtbnec

t1qtbnec1#

更改以下规则

"no-unused-vars": [
      "error", // -> make it off or warning
      { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }
    ],

字符串
如果你保持这个规则,那么每当TypeScript检测到任何未使用的变量时,你的代码都会抛出错误。

相关问题