Ask coding questions

← Back to all posts
SyntaxError: import declarations may only appear at top level of a module
[deleted]

I'm making a js library like p5.js when I run the repl it says
SyntaxError: import declarations may only appear at top level of a module

Answered by firefish [earned 5 cycles]
View Answer
Voters
dolphin30
Comments
hotnewtop
firefish

There are a couple of problems here:

is incorrect. You cannot use the import statement outside of a module. You need to do this instead:


However, the import statement must be used like this:

Note: the braces here, and the ./ (this means that it is in the current directory, which is needed otherwise js will complain)

dolphin30

wow, add me to it

[deleted]

It works, thanks