What's up with "import declarations may only appear at top level of a module"

So SpiderMonkey 52 supports ES6, and we're embedding the TypeScript 
compiler.  I got that part working but I get an error compiling the 
compiled scripts.

"compilation exception: import declarations may only appear at top level 
of a module: file: , line: 1"

This is my test program:

import Add from "./TSTest2";
let x:string='Hello from Typscript\n';

print_doc(x + Add(2,2).toString() + '\n');
// cause_an_error;

And this is the module it's trying to import:

export default function Add(x: number, y:number): number {
      return x + y;

When I google that error message, all the references to <script> tags in 
client side JS.  How do I get a server-side SpiderMonkey interpreter to 
not throw that error.

6/12/2018 10:05:52 PM
mozilla.dev.tech.js-engine 2017 articles. 0 followers. Post Follow

1 Replies

Similar Articles

[PageSpeed] 27

Sorry, I don't know the answer to this, but I would be very interested to f=
ind out if you manage to get it to work. I'm trying to upgrade our Spidermo=
nkey embedding from 1.8.5 and I have grabbed version 59. I'm very intereste=
d to know if/how ES6 features are enabled. Are they by default or do you ha=
ve to call some functions etc.
If you find the solution please can you post. Many thanks.
6/13/2018 8:58:21 AM