import-js/eslint-plugin-import

Cannot resolve `await import('https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js');`

adamlui opened this issue · 51 comments

https://github.com/adamlui/js-utils/blob/23b8bbb60944f8207e9793ad3ec021ffedb39f9e/geolocate/src/geolocate.js#L23

            await import('https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js');

results in error Unable to resolve path to module 'https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js' import/no-unresolved

Duplicate of #3107

Actually I tested using a random npm pkg with unminified js and same false positive

Image

.... so it appears this plugin cannot handle await import() syntax or URLs

Can you try running with DEBUG=eslint-plugin-import:* and sharing the output?

Sure

  eslint-plugin-import:resolver:node Resolving: https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js from: e:\js\utils\geolocate\src\geolocate.js +1s
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.jsdelivr.net/npm/generate-ip/dist/generate-ip.min.js' from 'e:\js\utils\geolocate\src'
    at resolveSync (e:\js\utils\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\js\utils\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\js\utils\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\js\utils\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\js\utils\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\js\utils\node_modules\eslint-module-utils\resolve.js:233:12)
    at checkSourceValue (e:\js\utils\node_modules\eslint-plugin-import\lib\rules\no-unresolved.js:40:53)
    at checkSourceValue (e:\js\utils\node_modules\eslint-module-utils\moduleVisitor.js:32:5)
    at checkImportCall (e:\js\utils\node_modules\eslint-module-utils\moduleVisitor.js:62:5)
    at ruleErrorHandler (e:\js\utils\node_modules\eslint\lib\linter\linter.js:1098:48) {
  code: 'MODULE_NOT_FOUND'
} +2ms

Also it happens using classic syntax too w/ the URL @ https://github.com/KudoAI/kudoai.com/blob/78a93d41671059713d26d081bb5a00d368311a1f/assets/js/matrix-bg.js#L1

import * as datGui from 'https://cdn.skypack.dev/dat.gui@0.7.7'

For that one it strangely tries multiple times

  eslint-plugin-import:resolver:node Resolving: https://cdn.skypack.dev/dat.gui@0.7.7 from: e:\kudoai\kudoai.com\assets\js\matrix-bg.js +127ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.skypack.dev/dat.gui@0.7.7' from 'e:\kudoai\kudoai.com\assets\js'
    at resolveSync (e:\kudoai\kudoai.com\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\kudoai\kudoai.com\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:233:12)
    at Function.get (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\exportMap\builder.js:37:45)
    at processBodyStatement (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\namespace.js:12:38)
    at e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\namespace.js:85:40
    at Array.forEach (<anonymous>) {
  code: 'MODULE_NOT_FOUND'
} +4ms
  eslint-plugin-import:resolver:node Resolving: https://cdn.skypack.dev/dat.gui@0.7.7 from: e:\kudoai\kudoai.com\assets\js\matrix-bg.js +7ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.skypack.dev/dat.gui@0.7.7' from 'e:\kudoai\kudoai.com\assets\js'
    at resolveSync (e:\kudoai\kudoai.com\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\kudoai\kudoai.com\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:233:12)
    at checkSourceValue (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\no-unresolved.js:40:53)
    at checkSourceValue (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\moduleVisitor.js:32:5)
    at checkSource (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\moduleVisitor.js:38:5)
    at ruleErrorHandler (e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\linter.js:1098:48) {
  code: 'MODULE_NOT_FOUND'
} +2ms
  eslint-plugin-import:resolver:node Resolving: https://cdn.skypack.dev/dat.gui@0.7.7 from: e:\kudoai\kudoai.com\assets\js\matrix-bg.js +3ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.skypack.dev/dat.gui@0.7.7' from 'e:\kudoai\kudoai.com\assets\js'
    at resolveSync (e:\kudoai\kudoai.com\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\kudoai\kudoai.com\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:233:12)
    at Function.get (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\exportMap\builder.js:37:45)
    at checkDefault (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\default.js:22:44)
    at ruleErrorHandler (e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\linter.js:1098:48)
    at e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\safe-emitter.js:45:58 {
  code: 'MODULE_NOT_FOUND'
} +1ms
  eslint-plugin-import:resolver:node Resolving: https://cdn.skypack.dev/dat.gui@0.7.7 from: e:\kudoai\kudoai.com\assets\js\matrix-bg.js +2ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.skypack.dev/dat.gui@0.7.7' from 'e:\kudoai\kudoai.com\assets\js'
    at resolveSync (e:\kudoai\kudoai.com\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\kudoai\kudoai.com\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:233:12)
    at defaultResolver (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\no-duplicates.js:320:112)
    at ImportDeclaration (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\no-duplicates.js:359:32)
    at ruleErrorHandler (e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\linter.js:1098:48)
    at e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\safe-emitter.js:45:58 {
  code: 'MODULE_NOT_FOUND'
} +10ms
  eslint-plugin-import:resolver:node Resolving: https://cdn.skypack.dev/dat.gui@0.7.7 from: e:\kudoai\kudoai.com\assets\js\matrix-bg.js +3ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.skypack.dev/dat.gui@0.7.7' from 'e:\kudoai\kudoai.com\assets\js'
    at resolveSync (e:\kudoai\kudoai.com\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\kudoai\kudoai.com\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:233:12)
    at Function.get (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\exportMap\builder.js:37:45)
    at checkDefault (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\no-named-as-default.js:29:51)
    at ruleErrorHandler (e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\linter.js:1098:48)
    at e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\safe-emitter.js:45:58 {
  code: 'MODULE_NOT_FOUND'
} +2ms
  eslint-plugin-import:resolver:node Resolving: https://cdn.skypack.dev/dat.gui@0.7.7 from: e:\kudoai\kudoai.com\assets\js\matrix-bg.js +1ms
  eslint-plugin-import:resolver:node resolve threw error: Error: Cannot find module 'https://cdn.skypack.dev/dat.gui@0.7.7' from 'e:\kudoai\kudoai.com\assets\js'
    at resolveSync (e:\kudoai\kudoai.com\node_modules\resolve\lib\sync.js:111:15)
    at exports.resolve (e:\kudoai\kudoai.com\node_modules\eslint-import-resolver-node\index.js:22:20)
    at withResolver (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:180:23)
    at fullResolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:201:22)
    at relative (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:217:10)
    at resolve (e:\kudoai\kudoai.com\node_modules\eslint-module-utils\resolve.js:233:12)
    at Function.get (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\exportMap\builder.js:37:45)
    at ImportDefaultSpecifier (e:\kudoai\kudoai.com\node_modules\eslint-plugin-import\lib\rules\no-named-as-default-member.js:39:50)
    at ruleErrorHandler (e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\linter.js:1098:48)
    at e:\kudoai\kudoai.com\node_modules\eslint\lib\linter\safe-emitter.js:45:58 {
  code: 'MODULE_NOT_FOUND'
} +2ms

e:\kudoai\kudoai.com\assets\js\matrix-bg.js
  1:20  error  Unable to resolve path to module 'https://cdn.skypack.dev/dat.gui@0.7.7'  import/no-unresolved
ljharb commented

This isn’t surprising because node doesn’t support importing URLs. To resolve something with a URL, you’d need a custom resolver.

(also, don’t use CDNs; always host your own assets)

This isn’t surprising because node doesn’t support importing URLs. To resolve something with a URL, you’d need a custom resolver.

So your plugin being marketed as "help validate proper imports," and https://github.com/KudoAI/kudoai.com/blob/78a93d41671059713d26d081bb5a00d368311a1f/assets/js/matrix-bg.js#L1

import * as datGui from 'https://cdn.skypack.dev/dat.gui@0.7.7'

...is valid JS import (properly resolves to help generate matrix code background @ https://kudoai.com) means your plugin should be expected to also lint URL imports like this successfully regardless of what node supports right, or are you only targeting node users

(also I intend to convert my other frontend pkgs like chatgpt.js to be node compatible eventually, then there will be import(url) still in codebase for frontend devs that will still be linted so the false positives will persist even if I myself pivot to targeting node)

(also, don’t use CDNs; always host your own assets)

I'm not rich sir <3 free jsDelivr (but I kinda agree when they go down my so many users are rekt)

ljharb commented

No, it’s not a valid JS import, it’s a valid browser import, which we don’t support.

Browser is not a language though, it is JS syntax (ES6) for 9 years and correctly resolved the resource so is valid JavaScript import and ESLint was made to lint JS (regardless of env) so I thought your plugin enhances the linter you're plugging into thus adheres to same principle of supporting all valid JS , but you have confirmed I am wrong (which is why I asked are you targeting node users only, again browser users also write in valid JS, but now I know the answer)

ljharb commented

The syntax is valid - but the spec doesn't talk about the specifier, and the URL comes from the WHATWG HTML specification, not the ecma-262 JavaScript specification.