Home > Mobile >  Export default in typescript isn´t working for commonjs
Export default in typescript isn´t working for commonjs

Time:08-04

im trying to make an express application but with typescript. With ts-node.

But when i try to export a function or class with export default it not works

helloWorld.ts

export default () => {
    console.log('Hello world!');
}


app.tss

import helloWorld from "./helloWorld.js";

helloWorld();

It returns the error: Error: Cannot find module './helloWorld.js'

CodePudding user response:

You are importing from .js extension (helloWorld.js) in your app.ts!

You should import from .ts extension or omit the extension

import helloWorld from "./helloWorld.ts";

or

import helloWorld from "./helloWorld";
  • Related