Skip to content

import/no-unresolved does not report none-existing function in Yarn workspace #1832

Open
@chrisdoc

Description

@chrisdoc

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions