How do I make tsconfig enforce that imports must include the .js extension?

12 views Asked by At

I migrated a Typescript Express project from CommonJS to ESM and now imports must include .js at the end.

For example, previously I would have

import {Foo} from "./Foo"

and now I need

import {Foo} from "./Foo.js"

That's fine, but my IDE (WebStorm) is still automatically importing without the extension and I'm only getting the error at compile time. Is there a way to modify my tsconfig so that this js extension is required?

This is my current tsconfig.json:

{
  "compilerOptions": {
    "module": "ES2022",
    "target": "es2022",
    "moduleResolution": "Node",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "baseUrl": "src",
    "allowSyntheticDefaultImports": true,
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}
0

There are 0 answers