Hello nostr!

I am trying to import NDK, but when i do i keep getting this error:

Uncaught SyntaxError: Cannot use import statement outside a module

What is a module? what am I doing wrong?

#asknostr

Reply to this note

Please Login to reply.

Discussion

Can I see your code?

It’s the difference between commons is and esm.

The import statement can be used in ESM.

Otherwise you shall use require().

It means you are trying to run the code on the “server” side

A module is a is code which uses ‘export’ statement.

To solve this problem I use Bun, it’s a runtime and a js bundler. With bun you can use both statements and it takes care about that shit.

You just have to bundle the code (build it in a single file) with a script. And target the correct environment (“node” if you want your code to be executed on the server, browser if you want it to run in the browser)