0

I get this error when I import public-key.js into my javascript file:

 import { decompress } from './public-key.js';  
 ^^^^^^
 SyntaxError: Unexpected token import  
 at createScript (vm.js:80:10)  
 at Object.runInThisContext (vm.js:139:10)  
 at Module._compile (module.js:617:28)  
 at Object.Module._extensions..js (module.js:664:10)  
 at Module.load (module.js:566:32)  
 at tryModuleLoad (module.js:506:12)  
 at Function.Module._load (module.js:498:3)  
 at Function.Module.runMain (module.js:694:10)  
 at startup (bootstrap_node.js:204:16)  
 at bootstrap_node.js:625:3  
Graham
  • 7,431
  • 18
  • 59
  • 84
  • Possible duplicate of [Node error: SyntaxError: Unexpected token import](https://stackoverflow.com/questions/37634198/node-error-syntaxerror-unexpected-token-import) – Jake Stewart Oct 07 '18 at 02:28

1 Answers1

0

Are you compiling from Typescript? If so, then I might be able to help. I had a similar message. I fixed it by using tsc main.ts --lib es2018 (replace main.ts with the name of your file) I think the problem had to do with it was compiling using an old ECMAScript version to compile. I had to use the command to change what it compiled with. You might be able to change it somewhere in the settings in order to not have to type that everytime you want to compile.

  • Update: add "lib": [ "es2018", "dom" ] to your tsconfig.json file if it does not do it automatically (you could use esnext or otherwise if you wanted. I just decided to use es2018 since it's the newest official release) – Chad McAdams Nov 05 '18 at 16:25