resolve-typescript-plugin is a webpack plugin designed to bridge the gap between TypeScript's ES Module output expectations and webpack's module resolution for ES Modules. It allows developers to import TypeScript files using a `.js` extension (e.g., `import { foo } from './bar.js'`) which aligns with native ES Module resolution behavior in Node.js and browsers, rather than webpack's default of requiring `.ts` or no extension. The current stable version is 2.0.1. Its release cadence has been infrequent since the introduction of an equivalent built-in feature in webpack. A key differentiator was solving the specific import extension problem for ESM TypeScript projects before webpack v5.74.0; now, its primary use case is for projects still on older webpack versions that require this specific resolution behavior. It is effectively in maintenance mode for older webpack versions, as webpack itself now offers `resolve.extensionAlias` for this functionality, making the plugin largely obsolete for modern webpack setups.
npm install resolve-typescript-pluginVerified import paths — ran on the pinned version, not inferred.
Illustrates how to integrate the plugin into a webpack configuration for an ES Module TypeScript project, enabling `.js` extension imports for `.ts` files.
Migrate your webpack configuration to use `resolve.extensionAlias`: `{ '.js': ['.ts', '.js'], '.mjs': ['.mts', '.mjs'] }` and remove `new ResolveTypeScriptPlugin()` from `resolve.plugins`.Upgrade your Node.js environment to version 14, 16, or 18+ to use versions 2.x of this plugin.
Ensure `resolve.fullySpecified` is not explicitly set to `true` in your webpack configuration when using this plugin, or remove it if present.
For webpack 4.x, name your configuration file `webpack.config.cjs` and use CommonJS `require()` syntax for imports/exports.
If needed, enable resolution within `node_modules` by configuring the plugin with `new ResolveTypeScriptPlugin({ includeNodeModules: true })`.Ensure `new ResolveTypeScriptPlugin()` is correctly added to `resolve.plugins` in your webpack config. Also, remove `.ts` and `.tsx` from your `resolve.extensions` array to avoid conflicts. For webpack >= 5.74.0, use `resolve.extensionAlias` instead of the plugin.
Ensure your webpack config aligns with the project's module type. If `"type": "module"` is in `package.json`, use `import` for the plugin and ensure the webpack config itself is an ESM module (e.g., `export default { ... }`). For CommonJS configs, use `const ResolveTypeScriptPlugin = require('resolve-typescript-plugin');`.