Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [BUG] 执行删除国际化命令报错 #10452

Closed
ZebraSu opened this issue Dec 19, 2022 · 27 comments
Closed

🐛 [BUG] 执行删除国际化命令报错 #10452

ZebraSu opened this issue Dec 19, 2022 · 27 comments

Comments

@ZebraSu
Copy link

ZebraSu commented Dec 19, 2022

🐛 bug 描述

执行 i18n-remove 终端报错 Error: Failed to load config "prettier" to extend from.

📷 复现步骤 | Recurrence steps

1、执行 pro create ant-app
2、选择 umi4
3、执行 yarn install
4、执行 i18n-remove
5、终端报错 Error: Failed to load config "prettier" to extend from.

🏞 期望结果 | Expected results

删除国际化相关配置

© 版本信息

  • ant-design/pro-cli": "^2.1.0"
  • umi 版本 umi4
  • 浏览器环境 Chrome
  • 开发环境 mac OS

🚑 其他信息

package.json

{
  "name": "ant-design-pro",
  "version": "6.0.0",
  "private": true,
  "description": "An out-of-box UI solution for enterprise applications",
  "scripts": {
    "analyze": "cross-env ANALYZE=1 max build",
    "build": "max build",
    "deploy": "npm run build && npm run gh-pages",
    "dev": "npm run start:dev",
    "gh-pages": "gh-pages -d dist",
    "i18n-remove": "pro i18n-remove --locale=zh-CN --write",
    "postinstall": "max setup",
    "jest": "jest",
    "lint": "npm run lint:js && npm run lint:prettier && npm run tsc",
    "lint-staged": "lint-staged",
    "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ",
    "lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src ",
    "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
    "lint:prettier": "prettier -c --write \"**/**.{js,jsx,tsx,ts,less,md,json}\" --end-of-line auto",
    "openapi": "max openapi",
    "prepare": "husky install",
    "prettier": "prettier -c --write \"**/**.{js,jsx,tsx,ts,less,md,json}\"",
    "preview": "npm run build && max preview --port 8000",
    "record": "cross-env NODE_ENV=development REACT_APP_ENV=test max record --scene=login",
    "serve": "umi-serve",
    "start": "cross-env UMI_ENV=dev max dev",
    "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev max dev",
    "start:no-mock": "cross-env MOCK=none UMI_ENV=dev max dev",
    "start:pre": "cross-env REACT_APP_ENV=pre UMI_ENV=dev max dev",
    "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_ENV=dev max dev",
    "test": "jest",
    "test:coverage": "npm run jest -- --coverage",
    "test:update": "npm run jest -- -u",
    "tsc": "tsc --noEmit"
  },
  "lint-staged": {
    "**/*.{js,jsx,ts,tsx}": "npm run lint-staged:js",
    "**/*.{js,jsx,tsx,ts,less,md,json}": ["prettier --write"]
  },
  "browserslist": ["> 1%", "last 2 versions", "not ie <= 10"],
  "dependencies": {
    "@ant-design/icons": "^4.7.0",
    "@ant-design/pro-components": "^2.3.37",
    "@ant-design/use-emotion-css": "1.0.4",
    "@umijs/route-utils": "^2.1.3",
    "antd": "^5.0.0",
    "classnames": "^2.3.2",
    "lodash": "^4.17.21",
    "moment": "^2.29.4",
    "omit.js": "^2.0.2",
    "rc-menu": "^9.6.4",
    "rc-util": "^5.24.4",
    "react": "^18.0.0",
    "react-dev-inspector": "^1.8.1",
    "react-dom": "^18.0.0",
    "react-helmet-async": "^1.3.0"
  },
  "devDependencies": {
    "@ant-design/pro-cli": "^2.1.0",
    "@testing-library/react": "^13.4.0",
    "@types/classnames": "^2.3.1",
    "@types/express": "^4.17.14",
    "@types/history": "^4.7.11",
    "@types/jest": "^29.2.1",
    "@types/lodash": "^4.14.186",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@types/react-helmet": "^6.1.5",
    "@umijs/lint": "^4.0.34",
    "@umijs/max": "^4.0.33",
    "cross-env": "^7.0.3",
    "eslint": "^8.0.0",
    "express": "^4.18.2",
    "gh-pages": "^3.2.0",
    "husky": "^7.0.4",
    "jest": "^29.2.2",
    "jest-environment-jsdom": "^29.2.2",
    "lint-staged": "^10.0.0",
    "mockjs": "^1.1.0",
    "prettier": "^2.7.1",
    "swagger-ui-dist": "^4.14.2",
    "ts-node": "^10.9.1",
    "typescript": "^4.8.4",
    "umi-presets-pro": "^2.0.0"
  },
  "engines": { "node": ">=12.0.0" }
}

【报错信息】
image

@ZebraSu
Copy link
Author

ZebraSu commented Dec 19, 2022

执行 yarn add eslint-config-prettier
yarn add eslint-plugin-unicorn 解决

@meihaoGit
Copy link

复现步骤 | Recurrence steps 相同
终端报错
Error: .eslintrc.js » /front-end/ant-app-v6/node_modules/@umijs/lint/dist/config/eslint/index.js:
Environment key "es2022" is unknown

这个怎么解决?

@meihaoGit
Copy link

image

@goddesses98
Copy link

node_modules/@umijs/lint/dist/config/eslint/index.js
// es2022: true

这样能解决问题, 目前应该是依赖的 eslint 有版本问题

@wudalei
Copy link

wudalei commented Dec 29, 2022

请问官方脚手架新建项目什么时候能修复这个问题呢?

@helloJincheng
Copy link

执行 yarn add eslint-config-prettier --dev yarn add eslint-plugin-unicorn --dev
然后修改node_modules/@umijs/lint/dist/config/eslint/index.js文件注释
// es2022: true可以解决问题

@SaGuLu
Copy link

SaGuLu commented Feb 26, 2023

@helloJincheng ,抱歉我刚刚接触前端框架,请问这里您提到的“然后修改node_modules/@umijs/lint/dist/config/eslint/index.js文件注释”中文件注释是什么意思,我不明白应该怎么操作才算有效?是直接在文件中写入注释“// es2022: true”吗?

此外,在 env 中本身有 es2022:true 的语句,我尝试了改成 es2021:true,发现可以正常执行国家化移除,但在前端界面中的侧边栏内容也跟着被移除了。

原文件中的内容如下:

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));

// src/config/eslint/index.ts
var import_recommended = __toESM(require("./rules/recommended"));
var import_setup = require("./setup");
module.exports = {
  parser: require.resolve("@babel/eslint-parser"),
  plugins: ["react", "react-hooks"],
  settings: {
    react: {
      version: "detect"
    }
  },
  env: {
    browser: true,
    node: true,
    es2022: true,
    jest: true
  },
  rules: import_recommended.default,
  overrides: [
    {
      parser: require.resolve("@typescript-eslint/parser"),
      plugins: ["@typescript-eslint/eslint-plugin"],
      files: ["**/*.{ts,tsx}"],
      rules: import_recommended.typescript
    },
    {
      settings: {
        jest: {
          version: detectJestVersion()
        }
      },
      files: ["**/*.{test,spec,unit,e2e}.{ts,tsx,js,jsx}"],
      plugins: ["jest"],
      rules: import_recommended.jest
    }
  ],
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    babelOptions: {
      babelrc: false,
      configFile: false,
      browserslistConfigFile: false,
      presets: [require.resolve("@umijs/babel-preset-umi")]
    },
    requireConfigFile: false
  }
};
function detectJestVersion() {
  try {
    const pkg = require.resolve("jest/package.json", {
      paths: [process.cwd()]
    });
    return require(pkg).version;
  } catch {
    return 29;
  }
}

@kisslove
Copy link

kisslove commented Mar 1, 2023

运行 i18n-remove 两个问题:
第一个:eslint的版本问题,可以尝试注释项目中.eslint.js的扩展部分跳过此错误。
第二个:会直接把默认的菜单配置移除掉,可以尝试在路由配置文件中加上name字段

@dlwstrong
Copy link

@PowerOfLov
这个问题最后该如何解决呢?

@dwyanedeng123
Copy link

@helloJincheng ,抱歉我刚刚接触前端框架,请问这里您提到的“然后修改node_modules/@umijs/lint/dist/config/eslint/index.js文件注释”中文件注释是什么意思,我不明白应该怎么操作才算有效?是直接在文件中写入注释“// es2022: true”吗?

此外,在 env 中本身有 es2022:true 的语句,我尝试了改成 es2021:true,发现可以正常执行国家化移除,但在前端界面中的侧边栏内容也跟着被移除了。

原文件中的内容如下:

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));

// src/config/eslint/index.ts
var import_recommended = __toESM(require("./rules/recommended"));
var import_setup = require("./setup");
module.exports = {
  parser: require.resolve("@babel/eslint-parser"),
  plugins: ["react", "react-hooks"],
  settings: {
    react: {
      version: "detect"
    }
  },
  env: {
    browser: true,
    node: true,
    es2022: true,
    jest: true
  },
  rules: import_recommended.default,
  overrides: [
    {
      parser: require.resolve("@typescript-eslint/parser"),
      plugins: ["@typescript-eslint/eslint-plugin"],
      files: ["**/*.{ts,tsx}"],
      rules: import_recommended.typescript
    },
    {
      settings: {
        jest: {
          version: detectJestVersion()
        }
      },
      files: ["**/*.{test,spec,unit,e2e}.{ts,tsx,js,jsx}"],
      plugins: ["jest"],
      rules: import_recommended.jest
    }
  ],
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    babelOptions: {
      babelrc: false,
      configFile: false,
      browserslistConfigFile: false,
      presets: [require.resolve("@umijs/babel-preset-umi")]
    },
    requireConfigFile: false
  }
};
function detectJestVersion() {
  try {
    const pkg = require.resolve("jest/package.json", {
      paths: [process.cwd()]
    });
    return require(pkg).version;
  } catch {
    return 29;
  }
}

@helloJincheng ,抱歉我刚刚接触前端框架,请问这里您提到的“然后修改node_modules/@umijs/lint/dist/config/eslint/index.js文件注释”中文件注释是什么意思,我不明白应该怎么操作才算有效?是直接在文件中写入注释“// es2022: true”吗?

此外,在 env 中本身有 es2022:true 的语句,我尝试了改成 es2021:true,发现可以正常执行国家化移除,但在前端界面中的侧边栏内容也跟着被移除了。

原文件中的内容如下:

var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));

// src/config/eslint/index.ts
var import_recommended = __toESM(require("./rules/recommended"));
var import_setup = require("./setup");
module.exports = {
  parser: require.resolve("@babel/eslint-parser"),
  plugins: ["react", "react-hooks"],
  settings: {
    react: {
      version: "detect"
    }
  },
  env: {
    browser: true,
    node: true,
    es2022: true,
    jest: true
  },
  rules: import_recommended.default,
  overrides: [
    {
      parser: require.resolve("@typescript-eslint/parser"),
      plugins: ["@typescript-eslint/eslint-plugin"],
      files: ["**/*.{ts,tsx}"],
      rules: import_recommended.typescript
    },
    {
      settings: {
        jest: {
          version: detectJestVersion()
        }
      },
      files: ["**/*.{test,spec,unit,e2e}.{ts,tsx,js,jsx}"],
      plugins: ["jest"],
      rules: import_recommended.jest
    }
  ],
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    babelOptions: {
      babelrc: false,
      configFile: false,
      browserslistConfigFile: false,
      presets: [require.resolve("@umijs/babel-preset-umi")]
    },
    requireConfigFile: false
  }
};
function detectJestVersion() {
  try {
    const pkg = require.resolve("jest/package.json", {
      paths: [process.cwd()]
    });
    return require(pkg).version;
  } catch {
    return 29;
  }
}

我也会自动移除侧边栏,你最后怎么解决的?

@xuzhougeng
Copy link

@dlwstrong @dwyanedeng123

简单的说就是,eslint跟当前的ant design pro不合。目前的解决方案总是有问题,会改掉route.tsx文件

这是修改前的route.tsx文件

export default [
  {
    path: '/user',
    layout: false,
    routes: [
      {
        name: 'login',
        path: '/user/login',
        component: './User/Login',
      },
    ],
  },
  {
    path: '/welcome',
    name: 'welcome',
    icon: 'smile',
    component: './Welcome',
  },
  {
    path: '/admin',
    name: 'admin',
    icon: 'crown',
    access: 'canAdmin',
    routes: [
      {
        path: '/admin',
        redirect: '/admin/sub-page',
      },
      {
        path: '/admin/sub-page',
        name: 'sub-page',
        component: './Admin',
      },
    ],
  },
  {
    name: 'list.table-list',
    icon: 'table',
    path: '/list',
    component: './TableList',
  },
  {
    path: '/',
    redirect: '/welcome',
  },
  {
    path: '*',
    layout: false,
    component: './404',
  },
];

这是修改后的文件

export default [
  { path: '/user', layout: false, routes: [{ path: '/user/login', component: './User/Login' }] },
  { path: '/welcome', icon: 'smile', component: './Welcome' },
  {
    path: '/admin',
    icon: 'crown',
    access: 'canAdmin',
    routes: [
      { path: '/admin', redirect: '/admin/sub-page' },
      { path: '/admin/sub-page', component: './Admin' },
    ],
  },
  { icon: 'table', path: '/list', component: './TableList' },
  { path: '/', redirect: '/welcome' },
  { path: '*', layout: false, component: './404' },
];

对比会发现,中间少了好多好多东西。所以,大家还是退回到UMI v3吧。

@xinxinClean
Copy link

我也遇到了

@YOOYY
Copy link

YOOYY commented Jun 3, 2023

所以目前为止,这个问题还没修复吗?

@kisslove
Copy link

kisslove commented Jun 5, 2023

@YOOYY 我的解决方法看我上面的方式。

@5201314999
Copy link

烦啊,早知道不用umi4 + ant-design-pro 了,pro-components 和 ant 也存在版本问题

1 similar comment
@5201314999
Copy link

烦啊,早知道不用umi4 + ant-design-pro 了,pro-components 和 ant 也存在版本问题

@5201314999
Copy link

5201314999 commented Jun 7, 2023

image 改成yarn 后,按上面eslint:2022 注释成功,然后日期组件只有年是中文,其它还是英文。。。

image

@5201314999
Copy link

日期问题已经解决 antd v5 手工 import 'dayjs/locale/zh-cn'; umi4 配置无效

@Xiaofeng05
Copy link

执行 yarn add eslint-config-prettier --dev yarn add eslint-plugin-unicorn --dev 然后修改node_modules/@umijs/lint/dist/config/eslint/index.js文件注释 // es2022: true可以解决问题

image
没删干净是怎么回事

@JuvenileQ
Copy link

注释掉ESLint配置文件的拓展试试。(我是重新安装的依赖,然后注释掉的就可以了)
image

@hateStudyy
Copy link

执行 yarn add eslint-config-prettier --dev yarn add eslint-plugin-unicorn --dev 然后修改node_modules/@umijs/lint/dist/config/eslint/index.js文件注释 // es2022: true可以解决问题

遇到两次这个bug了 把 es2022: true 这行注释掉就行了(官方什么时候修复啊!)

@jwaychen33
Copy link

尝试

为什么我在路由加了name也反应呀

@XunHua2023
Copy link

按这个方法解决了,谢谢

@flydo
Copy link

flydo commented Aug 9, 2023

问题真多,官方真的不知道有没有看的。
依赖也是,一堆 deprecated 的。

 ✂️  remove locale for src/app.tsx./home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/@eslint/eslintrc/lib/config-array/config-array.js:202
            throw new PluginConflictError(key, [
            ^

PluginConflictError: Plugin "react" was conflicted between ".eslintrc.js » /home/dev/workspaces/test/t1/node_modules/@umijs/lint/dist/config/eslint/index.js" and "BaseConfig".
    at mergePlugins (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/@eslint/eslintrc/lib/config-array/config-array.js:202:19)
    at createConfig (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/@eslint/eslintrc/lib/config-array/config-array.js:305:9)
    at ConfigArray.extractConfig (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/@eslint/eslintrc/lib/config-array/config-array.js:481:33)
    at Linter._verifyWithConfigArray (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/eslint/lib/linter/linter.js:1262:36)
    at Linter.verify (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/eslint/lib/linter/linter.js:1235:25)
    at Linter.verifyAndFix (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/eslint/lib/linter/linter.js:1428:29)
    at verifyText (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/eslint/lib/cli-engine/cli-engine.js:240:48)
    at CLIEngine.executeOnText (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/node_modules/eslint/lib/cli-engine/cli-engine.js:902:26)
    at eslintJS (/home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/src/i18n/eslintJs.js:10:25)
    at /home/dev/workspaces/test/t1/node_modules/@ant-design/pro-cli/src/i18n/index.js:63:32 {
  messageTemplate: 'plugin-conflict',
  messageData: {
    pluginId: 'react',
    plugins: [
      {
        filePath: '/home/dev/workspaces/test/t1/node_modules/@umijs/lint/node_modules/eslint-plugin-react/index.js',
        importerName: '.eslintrc.js » /home/dev/workspaces/test/t1/node_modules/@umijs/lint/dist/config/eslint/index.js'
      },
      {
        filePath: '/home/dev/workspaces/test/t1/node_modules/eslint-plugin-react/index.js',
        importerName: 'BaseConfig'
      }
    ]
  }
}

Node.js v18.16.0

@yanqi17118357
Copy link

把node_modules删掉执行没有报错

@ideaviewes
Copy link

这都4202年了,还不解决这个bug吗

@Ray-56
Copy link

Ray-56 commented Mar 14, 2024

已经解决了嘛?有人知道么。我用了新版还是同样的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests