【问题标题】:Eslint no-extraneous-dependencies error with npm workspacesnpm 工作空间的 Eslint 无外部依赖项错误
【发布时间】:2022-01-17 10:20:04
【问题描述】:

我已经使用具有以下高级结构的 NPM 工作区设置了我的 monorepo:

root
  common      // Shared package, named @company/common
    src
      ...
    package.json
    tsconfig.json
  web         // ReactJS package, named @company/web
    config
      ...
    public
      ...
    src
      ...
    package.json
    tsconfig.json
  mobile      // React Native package, named @company/mobile
    ...
    package.json
    tsconfig.json
  .eslintrc.json
  .prettierrc
  package.json
  tsconfig.json
  tsconfig.base.json

我所有的包都是私有的,并在它们各自的package.json 文件中被标记为私有。

我已经成功地完成了所有设置,以便我可以在 Web 和移动工作区中编写这样的代码:

import { ITestInterface } from '@company/common';

使用我当前的设置,每当我打开从@company/common 导入任何内容的任何文件时,我都会在我的 IDE(VS 代码)中收到 eslint 警告: '@company/common' should be listed in the project's dependencies. Run 'npm i -S @company/common' to add it

如果可能的话,我宁愿不完全禁用此警告。有没有办法配置 eslint 让它理解 monorepos,这样当我尝试从我的 monorepo 中的包(工作区)导入某些东西时它不会给我警告?

【问题讨论】:

    标签: eslint monorepo npm-workspaces


    【解决方案1】:

    也许将.eslintrc.json 移动到每个单独的包中?您是否尝试过在根目录下再次运行npm install

    我的设置是这样的,我没有这个问题。

    root
      back-end
        src/
        .eslintrc.js
        tsconfig.json
        tsconfig.ref.json
        package.json
      front-end
        src/
        .eslintrc.js
        tsconfig.json
        tsconfig.ref.json
        package.json
      shared
        // some .ts files
        package.json
    package.json
    tsconfig.json
    

    如果您想了解 tsconfig.ref.json,这里有一个如何设置它的示例:https://2ality.com/2021/07/simple-monorepos.html

    【讨论】:

      猜你喜欢
      • 2021-08-13
      • 1970-01-01
      • 2021-06-20
      • 2022-01-12
      • 2015-11-16
      • 2018-02-27
      • 2013-08-26
      • 2021-05-07
      • 2013-10-06
      相关资源
      最近更新 更多