next.js “需要禁用一些ESLint规则”错误,同时构建下一个js应用程序

lymnna71  于 2023-04-20  发布在  其他
关注(0)|答案(3)|浏览(499)

我想在服务器上部署我的Next.js文件。当我点击命令npm run build时,它显示错误
需要禁用一些ESLint规则?在此处了解更多信息:https://nextjs.org/docs/basic-features/eslint#disabling-rules
我无法找到错误,因为应用程序在localhost中正常工作,但当我想进行构建时,它显示错误。我的package.json文件中的包是

{
  "name": "yourguide-next-frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },
  "dependencies": {
    "@emotion/react": "^11.10.0",
    "@emotion/server": "^11.10.0",
    "@emotion/styled": "^11.9.3",
    "@mui/material": "^5.10.2",
    "@tinymce/tinymce-react": "^4.2.0",
    "cjs": "^0.0.11",
    "cookies": "^0.8.0",
    "js-cookie": "^3.0.1",
    "next": "12.2.3",
    "react": "18.2.0",
    "react-bootstrap": "^2.4.0",
    "react-dom": "18.2.0",
    "tinymce": "^6.1.2"
  },
  "devDependencies": {
    "@next/eslint-plugin-next": "^12.2.5",
    "eslint": "8.20.0",
    "eslint-config-next": "12.2.3"
  }
}

我不知道ESLint rules,请给予我这个问题的解决方案。

e0uiprwp

e0uiprwp1#

要在nextjs中构建时忽略eslint,您必须将这一行添加到next.config.js文件中:

eslint: {
    ignoreDuringBuilds: true,
},
70gysomp

70gysomp2#

最好能分享你在构建时得到的确切错误。
要禁用eslint的某些规则,您需要做的就是编辑您的.eslintrc.json文件,使其看起来像下面这样,或者您可以添加像https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-abusive-eslint-disable.md这样的注解

{   "env": {
    "browser": true,
    "es2021": true   },   "extends": [
    "plugin:react/recommended",
    "airbnb",
    "eslint:recommended",
    "plugin:prettier/recommended"   ],   "parser": "@babel/eslint-parser",   "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"   },   "plugins": [
    "react"   ],   "rules": {
    "react/react-in-jsx-scope": "off",
    "react/function-component-definition": [
      2,
      {
        "namedComponents": "arrow-function",
        "unnamedComponents": "arrow-function"
      }
    ],
    "no-use-before-define": [
      "error",
      {
        "functions": false,
        "classes": false,
        "variables": false
      }
    ],
    "react/no-unknown-property": 0,
    "no-console": 0,
    "no-plusplus": 0,   } }
bis0qfac

bis0qfac3#

我也得到了同样的错误,我通过从我的package.json中删除eslint依赖来修复它

相关问题