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?
CodePudding user response:
You can't. You need to compile the transcript files into js first.
CodePudding user response:
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.