0

I am trying to import a function for use in my main.ts file, but i either get 'is not a module' or 'unexpected import token' when i use node main.ts to run my file.

These are not node modules and i'm not using any framework.

// main.ts
import * as forms from "./script/form";

forms.autoForm();

// form.ts
export function autoForm() {
    // something
}
Paddy
  • 772
  • 2
  • 11
  • 28

1 Answers1

1

They are modules, and depending on your typescript configuration can be emitted as many different module formats.

Typescript is a compile time language, in order to run it it must be transformed into javascript first.

You can also see this question for details on how to run typescript files directly with node using tsc watch mode.

Community
  • 1
  • 1
caesay
  • 16,932
  • 15
  • 95
  • 160