Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Export default in typescript isn´t working for commonjs

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

app.tss

import helloWorld from "./helloWorld.js";

helloWorld();

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

>Solution :

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";
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading