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

import ES module #807

Open
entin-hun opened this issue Aug 29, 2024 · 7 comments
Open

import ES module #807

entin-hun opened this issue Aug 29, 2024 · 7 comments

Comments

@entin-hun
Copy link

entin-hun commented Aug 29, 2024

Following the guide, after successful yarn graphclient build I get stuck at import { execute } from '../.graphclient' .

  • If running as JS : SyntaxError: Cannot use import statement outside a module
  • If as .mjs : Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import './graphclient' is not supported resolving ES modules

Screenshot 2024-08-29 at 08 47 20

How should it be correctly?

@enisdenjo
Copy link
Member

As the error states, directory imports are not supported when resolving ESM modules. Try importing .graphclient/index.(m)js instead.

@entin-hun
Copy link
Author

As the error states, directory imports are not supported when resolving ESM modules. Try importing .graphclient/index.(m)js instead.

Thanks but there I only have .ts, and if I start my script with import { execute } from '../.graphclient/index.ts', then: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /root/opt/GETbc/.graphclient/index.ts

Could you please guide me further?

@enisdenjo
Copy link
Member

Try without extension 🤔

Also, please share the version you're using. Thanks!

@entin-hun
Copy link
Author

Try without extension 🤔

image

Also, please share the version you're using. Thanks!

image

@szekelyisz
Copy link

Don't you need to compile .graphclient/index.ts alongside your application sources? Check the include option in tsconfig.json.

@enisdenjo
Copy link
Member

Oh you're not compiling. Yes, you need to compile. You cant import raw TS files.

@entin-hun

This comment was marked as resolved.

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