graph-client icon indicating copy to clipboard operation
graph-client copied to clipboard

import ES module

Open entin-hun opened this issue 1 year ago • 7 comments

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?

entin-hun avatar Aug 29 '24 06:08 entin-hun

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

enisdenjo avatar Aug 29 '24 15:08 enisdenjo

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?

entin-hun avatar Aug 29 '24 18:08 entin-hun

Try without extension 🤔

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

enisdenjo avatar Aug 29 '24 18:08 enisdenjo

Try without extension 🤔 image

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

entin-hun avatar Aug 29 '24 19:08 entin-hun

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

szekelyisz avatar Aug 29 '24 21:08 szekelyisz

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

enisdenjo avatar Aug 30 '24 06:08 enisdenjo

yarn run tsc found 1047 errors in 30 files. 😭 Soo I tried to recreate exactly this guide in a subdir, but after both

  • yarn add -D @graphprotocol/client-cli
  • npm install --save-dev @graphprotocol/client-cli , including installing @graphprotocol/[email protected], graphclient build returns graphclient: command not found Why? 🤔

image

entin-hun avatar Aug 30 '24 20:08 entin-hun