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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Kent Williams
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.


_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

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

Miles Thornton
Sorry, I don't know the answer to this, but I would be very interested to find out if you manage to get it to work. I'm trying to upgrade our Spidermonkey embedding from 1.8.5 and I have grabbed version 59. I'm very interested to know if/how ES6 features are enabled. Are they by default or do you have to call some functions etc.
If you find the solution please can you post. Many thanks.
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine
Reply | Threaded
Open this post in threaded view
|

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

Jan de Mooij-2
In reply to this post by Kent Williams
You're probably trying to compile/execute the script as a plain script
instead of a module. See JS::CompileModule. There's also support for
modules in the JS shell (-m module I think), you could look at that as well.

Also, you might want to consider upgrading to ESR 60, its module support is
likely a lot better than what's in 52.

Hope this helps,
Jan

On Tue, Jun 12, 2018 at 3:05 PM, Kent Williams <[hidden email]>
wrote:

> 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.
>
>
> _______________________________________________
> dev-tech-js-engine mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
>
_______________________________________________
dev-tech-js-engine mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-js-engine