webpack does not find your .ts and .tsx files
Module not foundShort answer
Webpack tries only .js, .json and .wasm unless told otherwise, and it needs a loader before it can read TypeScript. Add .ts and .tsx to resolve.extensions, add a rule that sends them to ts-loader, and use resolve.extensionAlias if your imports end in .js while the real files are .ts.
Fix it fast
1Find out which cause you have
Run a development build and read the first error: it names the import and the folder webpack searched. Then open the config and look at resolve.extensions and module.rules.
npx webpack --mode development grep -n -A3 "extensions\|ts-loader" webpack.config.*2Match what you see, then jump to its fix
- 1
Import written without extension, such as import App from './App', and the file is App.tsx.resolve.extensions does not contain .ts and .tsxFix - 2
The build fails inside a .ts or .tsx file instead of at the import line.No rule sends .ts and .tsx files to a loaderFix - 3
Source such as import { f } from './helpers.js' where only helpers.ts exists.Imports end in .js but the real files are .tsFix
- 1
What does the error look like?
Module not foundCan't resolve
Cause 1 of 3
resolve.extensions does not contain .ts and .tsx
1Check
The default list is .js, .json and .wasm, and setting the option replaces that list.
grep -n -A3 "extensions" webpack.config.*2Fix
List the TypeScript extensions first. The token three dots keeps the defaults.
resolve: {
extensions: ['.tsx', '.ts', '...'],
},3Verify
The import resolves; the order matters if two files share a name.
npx webpack --mode developmentConfirmed by webpack.js.org
Cause 2 of 3
No rule sends .ts and .tsx files to a loader
1Check
The TypeScript guide sets up both the extension list and a module rule that sends .ts and .tsx files to ts-loader. Check that the rule exists and its test pattern matches both extensions.
grep -n -B1 -A4 "ts-loader" webpack.config.*2Fix
Install typescript and ts-loader and add the rule from the guide.
npm install --save-dev typescript ts-loader
// webpack.config.js
module: {
rules: [
{ test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/ },
],
},3Verify
The build compiles the file and the bundle is created.
npx webpack --mode developmentConfirmed by webpack.js.org
Cause 3 of 3
Imports end in .js but the real files are .ts
1Check
ESM-style TypeScript often writes the .js extension. Webpack looks for helpers.js on disk and does not find it.
ls src | grep helpers2Fix
Map the .js extension to the TypeScript extensions with resolve.extensionAlias.
resolve: {
extensionAlias: {
'.js': ['.ts', '.js'],
'.mjs': ['.mts', '.mjs'],
},
},3Verify
The import now resolves to the .ts file.
npx webpack --mode developmentConfirmed by webpack.js.org
How do I stop it coming back?
- Copy the resolve and rule blocks from the official TypeScript guide when you start a project.
- Keep extensions and extensionAlias in one place so editor and bundler agree.
- Run the production build in CI as well as the dev server.
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
A path alias works in the editor but not in the webpack build
Can't resolve
TypeScript paths only describe aliases to the compiler; webpack must be told too.
4 causes, each with a fixWeb 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 fix