How to import typescript file in javascript file

Viewed 49

I am trying to import a typescript file (src/index.ts) in a javascript file(tests/steps/utils.js)

But when I use const index_1 = require("../../src/index"); in my javascript file, it gives an error: Cannot find module '../../src/index'

But the file is right there. Is there any other way to import a typescript file into a javascript file?

2 Answers

You can't. You need to compile the transcript files into js first.

You can't import a ts into js file.

If you really need the module in .ts file, try to import from dist folder, where the ts compiler output path, or refactor into javascript.

Related