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

node/no-missing-import does not support node protocol #299

Open
k7sleeper opened this issue Oct 13, 2021 · 3 comments
Open

node/no-missing-import does not support node protocol #299

k7sleeper opened this issue Oct 13, 2021 · 3 comments

Comments

@k7sleeper
Copy link

import path from 'node:path'; fails incorrectly with message error "node:path" is not found node/no-missing-import (see node: Imports)

rwjblue added a commit to release-it-plugins/lerna-changelog that referenced this issue Oct 15, 2021
This works around an issue with node/no-missing-import that doesn't
properly see that `node:path` is a valid module on Node 12.x.

They are using `is-core-module` to figure out if it is a module or not,
and it seems that `is-core-module` doesn't differentiate between core
modules that are available for CJS (the `node:` prefixed paths are only
available in 14.18+ and 16+ in CJS files) and those that are available
to ESM.

This is really just a bandaid, the right fix would be to send a PR to
is-core-module to allow it to check CJS vs MJS modules (since they are
actually different).

See mysticatea/eslint-plugin-node#299
@rwjblue
Copy link

rwjblue commented Oct 15, 2021

I did some quick investigation here (as I ran into the same issue). It seems that this package is using is-core-module to determine if a given import is from a core module or not. Unfortunately, is-core-module doesn't currently have a way to check for the core modules that are available to packages using native ESM vs those still using CJS. This matters because Node's support is actually different in those contexts; you can't use require('node:path') in Node 12 but you can use import { join } from 'node:path' in Node 12.

@rwjblue
Copy link

rwjblue commented Oct 15, 2021

I opened an issue over in inspect-js/is-core-module#10 to see if there is any possibility to allow support for either CJS or MJS (as appropriate) over there.

rwjblue added a commit to release-it-plugins/lerna-changelog that referenced this issue Oct 15, 2021
This works around an issue with node/no-missing-import that doesn't
properly see that `node:path` is a valid module on Node 12.x.

They are using `is-core-module` to figure out if it is a module or not,
and it seems that `is-core-module` doesn't differentiate between core
modules that are available for CJS (the `node:` prefixed paths are only
available in 14.18+ and 16+ in CJS files) and those that are available
to ESM.

This is really just a bandaid, the right fix would be to send a PR to
is-core-module to allow it to check CJS vs MJS modules (since they are
actually different).

See mysticatea/eslint-plugin-node#299
@ljharb
Copy link

ljharb commented Oct 15, 2021

You can pass a "faked" node version to is-core-module, but you can also strip node: off of the core module name and pass that in.

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

No branches or pull requests

3 participants