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

Uncaught Error Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import #601

Open
nikolaypopadiuk opened this issue Oct 24, 2023 · 6 comments
Open

Comments

@nikolaypopadiuk
Copy link

Try running on https://vercel.com/

/home/codespace/nvm/current/bin/node ./api/telegram.mjs
Process exited with code 1
Uncaught Error Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/workspaces/project_name/node_modules/telegram/sessions' is not supported resolving ES modules imported from /workspaces/project_name/api/telegram.mjs
Did you mean to import telegram/sessions/index.js?
at __node_internal_captureLargerStackTrace (node:internal/errors:497:5)
at NodeError (node:internal/errors:406:5)
at finalizeResolution (node:internal/modules/esm/resolve:227:11)
at moduleResolve (node:internal/modules/esm/resolve:845:10)
at defaultResolve (node:internal/modules/esm/resolve:1043:11)
at defaultResolve (node:internal/modules/esm/loader:383:12)
at resolve (node:internal/modules/esm/loader:352:25)
at getModuleJob (node:internal/modules/esm/loader:228:38)
at (node:internal/modules/esm/module_job:85:39)
at link (node:internal/modules/esm/module_job:84:36)
--- await ---
at runMainESM (node:internal/modules/run_main:53:21)
at executeUserEntryPoint (node:internal/modules/run_main:79:5)
at (node:internal/main/run_main_module:23:47)

@old-mikser
Copy link

same issue

@awdr74100
Copy link

The same problem also occurred on the "type": "module" node.js project.

@MR4online
Copy link

changing the import fixed it for me:

import { StringSession } from "telegram/sessions/index.js";

see https://stackoverflow.com/questions/64449464/error-err-unsupported-dir-import-directory-import-when-attempting-to-start-no

@lollobene
Copy link

SAVER

changing the import fixed it for me:

import { StringSession } from "telegram/sessions/index.js";

see https://stackoverflow.com/questions/64449464/error-err-unsupported-dir-import-directory-import-when-attempting-to-start-no

@SkuratovichA
Copy link

SkuratovichA commented Jun 9, 2024

I have the same issue.

None of those work:
image

I get the same error
image

package.json

{
  ...
  "type": "module",
  "main": "index.js",
  "scripts": {
  ...
    "build": "rm -rf dist && swc src --out-dir dist --strip-leading-paths",
    "start": "node dist/index.js"
  }
  ... 

tsconfig.json

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "incremental": true,
    "esModuleInterop": true,
    "outDir": "dist",
    "rootDir": "src",
    "noEmit": false
  }
}

.swcrc

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false,
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "esnext"
  },
  "module": {
    "type": "es6"
  },
}

@painor
Copy link
Member

painor commented Dec 25, 2024

as a workaround you can do.

  client.addEventHandler((message) => {
        console.log(message);
    }, new TelegramClient.events.NewMessage());

You don't need to import events like this.

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

7 participants