Re: What's up with "import declarations may only appear at top level of a module"
Jan de Mooij <[email protected]> Wed, 13 Jun 2018 09:00:58 -0700
| Newsgroups | gmane.comp.mozilla.devel.jseng |
|---|---|
| Message-ID | <CABTC+Jd92tVsL3AxP6FFjnk-gCg1bgN988TMJuK6tebXGxzgzg@mail.gmail.com> |
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 <[email protected]> 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 > [email protected] > https://lists.mozilla.org/listinfo/dev-tech-js-engine >