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

ERR_UNSUPPORTED_DIR_IMPORT when importing npm package #26477

Open
tsalsa919 opened this issue Oct 22, 2024 · 1 comment
Open

ERR_UNSUPPORTED_DIR_IMPORT when importing npm package #26477

tsalsa919 opened this issue Oct 22, 2024 · 1 comment
Labels
upstream Changes in upstream are required to solve these issues

Comments

@tsalsa919
Copy link

Version: Deno 2.0.2

Just try to use node-hue-api in Deno. And I see that it yield in ERR_UNSUPPORTED_DIR_IMPORT. Seems like it is due to the the way how .js/.ts/.mjs extension are handled in the file. Is there a way to pass --experimental-specifier-resolution=node to import to fix this.

deno install npm:node-hue-api

main.ts file:
import * as hue from 'npm:node-hue-api'

deno run main.ts
Got the following errors from the console.

error: [ERR_UNSUPPORTED_DIR_IMPORT] Directory import 'file:///<project_dir>/node_modules/.deno/[email protected]/node_modules/node-hue-api/dist/esm/api/discovery' is not supported resolving ES modules imported from 'file:///<project_dir>/node_modules/.deno/[email protected]/node_modules/node-hue-api/dist/esm/index.js'

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented Oct 23, 2024

Looking at the code they ship in the node-hue-api package it seems like they're distributing files in ESM syntax, but expect CommonJS resolution. The same error is thrown when you try to import that package in Node with ESM.

node:internal/modules/esm/resolve:259
    throw new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath(base), String(resolved));
          ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/<project>/node_modules/node-hue-api/dist/esm/api/discovery' is not supported resolving ES modules imported from /<project>/node_modules/node-hue-api/dist/esm/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:259:11)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///<project>/node_modules/node-hue-api/dist/esm/api/discovery'
}

It's an unfortunate situation, because the package say that they support ESM, but it turns out that they do not. They have an issue for that in their tracker already peter-murray/node-hue-api#220

@marvinhagemeister marvinhagemeister added the upstream Changes in upstream are required to solve these issues label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

2 participants