How to import a JS library installed in node modules

I am trying to import a library in a doctype js file , but putting import in the top of the file results in the following error message:
Uncaught SyntaxError: import declarations may only appear at top level of a module.
What is a correct way is to import a library ?