umijs / fabric

💪严格但是不严苛的编码规范
640 stars 102 forks source link

[求助]eslint 一直报找不到`@babel/plugin-proposal-decorators` #122

Open dadazhouRenee opened 2 years ago

dadazhouRenee commented 2 years ago

node: 12.22.0 yarn: 1.22.17 farbic version: 2.6.6 依赖:

"devDependencies": {
    "@ant-design/compatible": "^1.0.8",
    "@types/react": "^16.4.11",
    "@types/react-dom": "^16.0.6",
    "@umijs/fabric": "2.6.6",
    "@umijs/plugin-qiankun": "^2.35.2",
    "@umijs/preset-react": "^1.8.4",
    "cross-env": "^5.1.1",
    "cross-port-killer": "^1.0.1",
    "enzyme": "^3.4.4",
    "eslint": "^7.30.0",
    "gh-pages": "^1.2.0",
    "lint-staged": "^12.3.3",
    "merge-umi-mock-data": "^0.0.3",
    "mockjs": "^1.0.1-beta3",
    "prettier": "2.3.2",
    "pro-download": "^1.0.1",
    "stylelint": "^14.5.0",
    "umi": "^3.5.20"
  }

编辑器报错

Parsing error: Cannot find module '@babel/plugin-proposal-decorators'
Require stack:
- D:\xxx\node_modules\@babel\core\lib\config\files\plugins.js
- D:\xxx\node_modules\@babel\core\lib\config\files\index.js
- D:\xxx\node_modules\@babel\core\lib\index.js
- D:\xxx\node_modules\@babel\eslint-parser\lib\worker\babel-core.cjs
- D:\xxx\node_modules\@babel\eslint-parser\lib\worker\handle-message.cjs
- D:\xxx\node_modules\@babel\eslint-parser\lib\client.cjs
- D:\xxx\node_modules\@babel\eslint-parser\lib\index.cjs
- D:\xxx\node_modules\@eslint\eslintrc\lib\config-array-factory.js
- D:\xxx\node_modules\@eslint\eslintrc\lib\index.js
- D:\xxx\node_modules\eslint\lib\cli-engine\cli-engine.js
- D:\xxx\node_modules\eslint\lib\cli-engine\index.js
- D:\xxx\node_modules\eslint\lib\api.js

但是 node_modules可以找到plugin-proposal-decorators 1644560262(1) 请问这是什么原因呢

gary-Shen commented 2 years ago

+1

ipoto commented 2 years ago

在tsconfig.json的include加上.eslintrc.js,"include": ["mock//*", "src/*/", "config//*", ".umirc.ts", "typings.d.ts", ".eslintrc.js"],

yunsii commented 2 years ago

我现在是 JS 项目会这样,令人窒息

yunsii commented 2 years ago

终于搞懂了,我手动按着依赖往上一层层找确实找不到依赖,果然代码是不会骗人的 _(:з」∠)_ 研究了很久,发现因为我是用的 pnpm,而 pnpm 默认创建的是半严格的 node_modules 导致的问题,可通过配置 shamefully-hoist 暴力解决,我目前配置的是 public-hoist-pattern[]=*@babel*

Renderz commented 2 years ago

public-hoist-pattern[]=@babel

直接配shamefully-hoist=true再重装依赖好像就可以了

yunsii commented 2 years ago

public-hoist-pattern[]=@babel

直接配shamefully-hoist=true再重装依赖好像就可以了

这是最暴力的解决方案,倒是看到不少开源库也是这么干的

superbogy commented 2 years ago

+1