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

import/no-unresolved fails to find missing dependencies within a workspace #1688

Closed
jamesarosen opened this issue Mar 17, 2020 · 4 comments
Closed

Comments

@jamesarosen
Copy link

I have a Yarn workspace with the following structure:

- package.json
- packages/
   - myPackage/
      - package.json
      - index.js

In ./package.json, I have

"name": "@my/workspace",
"devDependencies": {
  "@storybook/addon-knobs": "^5.0.10"
}

That adds react-transition-group through the following dependency tree:

@my/workspace@0.0.1
└─┬ @storybook/addon-knobs@5.0.10
  └─┬ react-select@2.4.3
    └── react-transition-group@2.9.0

In ./packages/myPackage/index.js, I have

import { CSSTransition } from 'react-transition-group'

but I don't declare a direct dependency from @my/package to react-transition-group.

import/no-unresolved finds no problems. But if I publish @my/package, it (naturally) doesn't have access to react-transition-group.

@jamesarosen
Copy link
Author

This also happens with other packages within the same workspace. So given

// packages/one/index.js
import Two from "@my/two"
export default function One() {
  return <span class='one'><Two /></span>
}


// packages/two/index.js

export default function Two() {
  return <span class='two'></span>
}

import/no-unresolved reports no problems even if packages/one/package.json declares no dependency on "@my/two".

@ljharb
Copy link
Member

ljharb commented Mar 18, 2020

no-unresolved only checks what's in node_modules; not what will be there when you publish it.

no-extraneous-dependencies is the rule you want to be using, which will ensure that everything you import/require is actually in your package.json.

@jamesarosen
Copy link
Author

Thanks for that, @ljharb!

I have

'import/no-extraneous-dependencies': context => [
  'error',
  {
    devDependencies: false,
    packageDir: [context.getFilename(), __dirname],
  },
],

in my root package.json so I can use dev dependencies from the root workspace in each package to work around #458. Maybe I need to narrow down the list of files that matches.

@bertho-zero
Copy link

I can not do like @jamesarosen, I have this error:

Error: .eslintrc » @openagenda/eslint-config:
        Configuration for rule "import/no-extraneous-dependencies" is invalid:
        Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '[Function: import/no-extraneous-dependencies]').

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

No branches or pull requests

3 participants