Cannot import TypeScript modules without providing a file extension

I am very new to TypeScript and I expect that I can import TS files without having to indicate that they are TS files.

I need to do

import {sealed} from "./decorators/decorators.ts"; 

instead of what I want to think, this is the right way, which

 import {sealed} from "./decorators/decorators"; 

leading to errors indicating that it is looking for files ending in .js or .jsx

my tsconfig.json looks like this

 { "compileOnSave": true, "compilerOptions": { "module": "commonjs", "moduleResolution": "node", "jsx": "react", "allowJs": true, "target": "es6", "removeComments": true, "experimentalDecorators": true, "emitDecoratorMetadata": true }, "exclude": [ "node_modules", "typings/browser", "typings/browser.d.ts" ] 

}

+5
source share
1 answer

If you are using webpack, try adding this to your webpack.config.js file:

 resolve: { extensions: ['', '.js', '.jsx', '.ts', '.tsx'] }, 
+5
source

Source: https://habr.com/ru/post/1246749/


All Articles