Can't import a typescript file

- I'm using Intellij  2022.1.1 Ultimate Edition with Windows 11
- I have a standard ES6 nodeJs project (standard Es6 code, no typescript), and I want to import some typescript files in it.

ex : 

import * as MongoDb from "../../../../../libs/node/mongoDb5/index.ts"

I have the following error : "Uncaught TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for D:\Dev\webDevGx\libs\node\mongoDb5\index.ts"

I've never use Typescript before, maybe I made a beginner's mistake.

Thanks for your help

 

 

 

评论操作 固定链接

How do you run your code? Typescript files can't be executed directly, they have to be pre-compiled. See https://stackoverflow.com/questions/69262102/having-error-keeps-saying-unknown-file-extension for some hints

0
评论操作 固定链接

I taught Intellij would "auto compile" the ts file by itself, at that it was just a question of settings.

0
评论操作 固定链接

You can enable Recompile on changes in Settings | Languages & Frameworks | TypeScript to have the files auto-compiled; but still you need importing a resultant *.js file and not a *.ts

0

请先登录再写评论。