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 does not report none-existing function in Yarn workspace #1832

Open
chrisdoc opened this issue Jun 19, 2020 · 7 comments

Comments

@chrisdoc
Copy link

I noticed that import/no-unresolved is not warning me when I forgot to export a function from a Yarn workspace which will be imported from another Yarn workspace.

I created a minimal repo https://github.com/chrisdoc/eslint-plugin-import-bug-minimal-repo which consists of two workspaces foo and bar.

.
├── .eslintrc.js
├── .gitignore
├── bar
│   ├── index.js
│   └── package.json
├── foo
│   ├── index.js
│   └── package.json
├── LICENSE
├── package.json
├── README.md
└── yarn.lock

Inside foo/index.js there is a single function helloFoo which is exported so that it can be consumed by bar

function helloFoo() {
  // eslint-disable-next-line no-console
  console.log('hello foo');
}

module.exports = { helloFoo };

Now in bar/index.js I import both helloFoo and a none existing helloFooV2 via:

const { helloFoo, helloFooV2 } = require('@my/foo');

Now when I run yarn lint no errors are reported:

yarn lint
yarn run v1.22.4
$ eslint .
✨  Done in 1.23s.

When I then try to execute yarn bar which calls bar/index.js NodeJS fails due to calling helloFooV2 which does not exist.

yarn run v1.22.4
$ yarn workspace @my/bar start
$ node index.js
hello foo
/Users/chrisdoc/dev/eslint-plugin-import-bug-minimal-repo/bar/index.js:4
helloFooV2();
^

TypeError: helloFooV2 is not a function
    at Object.<anonymous> (/Users/chrisdoc/dev/eslint-plugin-import-bug-minimal-repo/bar/index.js:4:1)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1025:10)
    at internal/main/run_main_module.js:17:11
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/chrisdoc/.nvm/versions/node/v12.13.0/bin/node
Arguments: /Users/chrisdoc/.yarn/lib/cli.js start
Directory: /Users/chrisdoc/dev/eslint-plugin-import-bug-minimal-repo/bar
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here you can see an example being run on Github Workflows that shows that yarn lint succeeds and that yarn bar fails

https://github.com/chrisdoc/eslint-plugin-import-bug-minimal-repo/runs/787914292

@ljharb
Copy link
Member

ljharb commented Jun 19, 2020

I assume this is because the ExportMap doesn't traverse symlinks - does it fail as expected when things are installed, not symlinked in?

@SanjiKir
Copy link

I have the same issue in monorepo. import/named doesn't check private yarn workspaces.

@ljharb
Copy link
Member

ljharb commented Aug 3, 2020

@SanjiKir you'd have to provide a custom resolver if you have a custom layout, including any "workspaces" things.

@jd2rogers2

This comment has been minimized.

@ljharb

This comment has been minimized.

@jd2rogers2

This comment has been minimized.

@ljharb

This comment has been minimized.

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

4 participants