Skip to content
Advertisement

unexpected token import/export – typescript

I’m trying out typescript for the first time and am confused about the import/export procedures that I am used to using with es6.

this is an interface I am trying to export in a file called transformedRowInterface.ts:

JavaScript

and this is my attempt to import, in a file called newsArticleModel.ts:

JavaScript

this is my tsconfig:

JavaScript

What am I doing wrong?

Advertisement

Answer

I’m pretty sure this is because you are targeting ES2017, which supports the syntax for imports “out of the box”, i.e. your output would literally contain

JavaScript

If your runtime doesn’t support this kind of import, you will need to use down-level compilation (i.e. target ES5) so the import gets converted into the CommonJS require call.

You can test my theory by looking at the JavaScript output to see what the import looks like.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement