ESLint asks for a .ts extension on imports that work fine
Missing file extension "ts"Short answer
The import/extensions rule demands or forbids file extensions per file type. When ts and tsx are not in its list, a config such as always makes it ask for them on every import. Add ts and tsx with never for plain bundler or ts-node style code, and keep always only if you run native ESM.
Fix it fast
1Find out which cause you have
Find the import/extensions setting that is active, including the one inherited from a shared config.
npx eslint --print-config src/index.ts | grep -n "import/extensions" -A82Match what you see, then jump to its fix
What does the error look like?
Missing file extension "ts"import/extensions
Cause 1 of 2
ts and tsx are missing from the per-extension map
1Check
The rule accepts a string as the default plus an object that overrides single extensions. Without a ts entry, the default applies to ts files.
grep -rn "import/extensions" eslint.config.* .eslintrc* package.json 2>/dev/null2Fix
Keep your default, and declare ts and tsx as never so extensionless imports pass.
"import/extensions": [
"error",
"ignorePackages",
{ "ts": "never", "tsx": "never" }
]3Verify
Lint the file that failed.
npx eslint src/index.tsConfirmed by raw.githubusercontent.com
Cause 2 of 2
The project runs as native ESM, where extensions are required
1Check
Node.js does not support extensionless relative paths in import statements. TypeScript expects the written extension to be .js and maps it to the .ts file.
grep -n "\"module\"\|moduleResolution" tsconfig.json2Fix
Do not turn the rule off. Write imports with the .js extension and set the rule to always for js.
import { slugify } from './utils.js';
"import/extensions": ["error", "ignorePackages", { "js": "always", "ts": "never" }]3Verify
Lint and run the compiled output.
npx eslint src
npx tsc && node dist/index.jsConfirmed by typescriptlang.org
How do I stop it coming back?
- Decide once whether the project uses extensionless or .js imports, and set the rule to match.
- Check shared configs with --print-config after upgrading them.
- Let tsc, not ESLint, be the authority on whether an import path resolves.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Back end
TypeScript cannot find '@angular/platform-browser' in an Angular project
Cannot find module '@angular/platform-browser' or its corresponding type declarations.
TS2307 means TypeScript could not turn the import into a file.
3 causes, each with a fixBack end
Angular build fails with TS2707 or "has no exported member" after installing a library
Module '"@angular/core"' has no exported member
These errors mean a library was compiled by a newer Angular than your app uses.
3 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
TypeScript cannot find module '@nestjs/core' or its type declarations
error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
TS2307 means TypeScript searched node_modules and found neither the package nor its types.
3 causes, each with a fixBack end
Mocha or Node cannot find ts-node/register
Error: Cannot find module 'ts-node/register'
Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.
2 causes, each with a fixBack end
TypeError: Class constructor cannot be invoked without 'new' in compiled TypeScript
TypeError: Class constructors cannot be invoked without 'new'
Node.js throws this when a native class is called like a plain function.
2 causes, each with a fix