TypeScript rejects an import that ends in .ts
An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.Short answer
TypeScript refuses a .ts import because it never rewrites the specifier, so the emitted JavaScript would point at a file that does not exist. Pick one way out: allow it with allowImportingTsExtensions plus noEmit when a bundler or runtime handles the code, let tsc rewrite it with rewriteRelativeImportExtensions, or drop the extension.
Fix it fast
1Find out which cause you have
Find out whether tsc writes JavaScript for this project and which TypeScript version it is. The answer decides which fix below is allowed.
npx tsc --version grep -nE "noEmit|emitDeclarationOnly|allowImportingTsExtensions|rewriteRelativeImportExtensions|moduleResolution" tsconfig.json2Match what you see, then jump to its fix
- 1
tsc is only used for type checking (noEmit), and webpack, Vite, tsx or Deno runs the code.A bundler or TypeScript runtime consumes the files, so no JavaScript needs to come from tscFix - 2
You build with tsc into dist and want to write imports like ./math.ts in the source.tsc emits the JavaScript that you ship, so the .ts path would reach runtimeFix - 3
The project is bundled with webpack, Vite or similar and nothing requires the extension.The extension was never needed under a bundler-style resolutionFix
- 1
What does the error look like?
An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled.
Cause 1 of 3
A bundler or TypeScript runtime consumes the files, so no JavaScript needs to come from tsc
1Check
If your build does not use tsc output, the rule that protects emitted JavaScript does not matter for you.
grep -nE "noEmit|emitDeclarationOnly" tsconfig.json2Fix
Turn on allowImportingTsExtensions together with noEmit. The flag is only allowed when noEmit or emitDeclarationOnly is set.
{
"compilerOptions": {
"allowImportingTsExtensions": true,
"noEmit": true
}
}3Verify
Type checking passes and the import keeps its .ts extension.
npx tsc -p tsconfig.jsonConfirmed by typescriptlang.org
Cause 2 of 3
tsc emits the JavaScript that you ship, so the .ts path would reach runtime
1Check
allowImportingTsExtensions would be refused here because the output would contain .ts paths. TypeScript 5.7 added an option that rewrites them.
npx tsc --version2Fix
Enable rewriteRelativeImportExtensions. Relative specifiers ending in .ts, .tsx, .mts or .cts are rewritten to .js, .jsx, .mjs or .cjs in the output. Bare package paths, aliased paths and dynamic imports with computed paths are not rewritten.
{
"compilerOptions": {
"rewriteRelativeImportExtensions": true
}
}3Verify
Build, then open the emitted file and check that the import now ends in .js.
npx tsc -p tsconfig.json
grep -rn "from \"./" dist | headConfirmed by typescriptlang.org
Cause 3 of 3
The extension was never needed under a bundler-style resolution
1Check
With moduleResolution set to bundler, extensionless relative imports work the way they do in CommonJS.
grep -n moduleResolution tsconfig.json2Fix
Use the bundler resolution and remove the extension from the import. Webpack finds the file through resolve.extensions.
// tsconfig.json: "moduleResolution": "bundler"
// before
import { add } from "./math.ts";
// after
import { add } from "./math";3Verify
tsc passes without any new compiler flag.
npx tsc --noEmit -p tsconfig.jsonConfirmed by typescriptlang.org
How do I stop it coming back?
- Decide once whether tsc emits code or only checks types, and set noEmit in the same commit.
- Use moduleResolution bundler for apps and node16 or nodenext for libraries that Node.js loads directly.
- Run tsc --noEmit in CI so a stray .ts import fails before a build.
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.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
Cypress refuses to start with 'Your configFile is invalid'
Your configFile threw an error from: /path/to/cypress.config.ts
Cypress could not load cypress.config.js or .ts, or found something wrong in it.
5 causes, each with a fixWeb apps
ESLint cannot decide which copy of the @typescript-eslint plugin to use
The message lists two file paths for the same plugin, each with the name of the config that loaded it
ESLint found the same plugin at two different file paths and will not pick one.
3 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint was configured to run using parserOptions.project, but the file is not in the TSConfig
However, that TSConfig does not include this file
Type-aware linting needs every linted file to belong to a TypeScript project.
4 causes, each with a fixWeb apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fix