{"id":19737780,"url":"https://github.com/softwareventures/resolve-typescript-plugin","last_synced_at":"2025-04-30T05:30:45.281Z","repository":{"id":37781873,"uuid":"360337210","full_name":"softwareventures/resolve-typescript-plugin","owner":"softwareventures","description":"webpack plugin to resolve TypeScript files when importing with js file extension in ESM projects","archived":false,"fork":false,"pushed_at":"2024-05-27T21:16:17.000Z","size":5554,"stargazers_count":45,"open_issues_count":11,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-28T07:25:02.714Z","etag":null,"topics":["esm","plugin","resolve","typescript","webpack"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/resolve-typescript-plugin","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softwareventures.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-21T23:44:37.000Z","updated_at":"2024-05-29T21:17:06.510Z","dependencies_parsed_at":"2023-09-24T02:24:19.521Z","dependency_job_id":"7b25f237-d4c8-4c88-b42b-555b9eb69581","html_url":"https://github.com/softwareventures/resolve-typescript-plugin","commit_stats":{"total_commits":417,"total_committers":6,"mean_commits":69.5,"dds":0.5347721822541966,"last_synced_commit":"91a7edea93521d68233d2ef450ea00b57a13f30c"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareventures%2Fresolve-typescript-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareventures%2Fresolve-typescript-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareventures%2Fresolve-typescript-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareventures%2Fresolve-typescript-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softwareventures","download_url":"https://codeload.github.com/softwareventures/resolve-typescript-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224197895,"owners_count":17271999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esm","plugin","resolve","typescript","webpack"],"created_at":"2024-11-12T01:12:20.172Z","updated_at":"2024-11-12T01:12:20.842Z","avatar_url":"https://github.com/softwareventures.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# resolve-typescript-plugin\n\nA webpack plugin to resolve TypeScript files imported using the `.js` extension\nwhen using ESM imports.\n\n## Obsolete\n\nwebpack has equivalent functionality built-in since v5.74.0. This plugin is no\nlonger needed unless you are using an older version of webpack.\n\nTo migrate from this plugin, set `resolve.extensionAlias` in\n`webpack.config.js`:\n\n```js\nexport default {\n    resolve: {\n        extensionAlias: {\n            \".js\": [\".ts\", \".js\"],\n            \".mjs\": [\".mts\", \".mjs\"]\n        }\n    }\n};\n```\n\nand remove `new ResolveTypeScriptPlugin()` from `resolve.plugins`.\n\nFor the time being this plugin is still maintained for the benefit of people who\nuse older versions of webpack.\n\n## Why?\n\nIf you are using webpack in conjunction with TypeScript and ES Modules, you need\nthis plugin for full compliance with the ES Modules ecosystem.\n\nES Modules require imports to specify the runtime path of the file to be\nimported, including file extension. For TypeScript files, this means that [you\nmust import using the extension `.js`][1] even though the source file uses the\nextension `.ts` or `.tsx`. This is because TypeScript compiles to a `.js` file\nthat will be used at runtime.\n\nHowever, webpack behaves differently, even when configured for ES Modules.\nwebpack expects that files will be imported by specifying the compile-time path\nof the file, including the compile-time extension. For TypeScript files this\nwill be `.ts` or `.tsx`. Alternatively, webpack expects that files will be\nimported with no extension, in which case webpack will resolve the extension\nautomatically according to the [`resolve.extensions` option][2]. Neither of\nthese behaviours is consistent with browser or node ES Module environments.\n\nThis plugin extends webpack module resolution so that imports specifying a `.js`\nextension will resolve to the corresponding `.ts` or `.tsx` file if available,\nand fall back to `.js` otherwise.\n\nIf you want to create ES Modules in TypeScript that are consistent between\nwebpack, browser, and node environments, use this plugin.\n\nSee [ts-loader#1110][3] for more background on this issue.\n\n## Install\n\nWith npm:\n\n```bash\nnpm install --save-dev resolve-typescript-plugin\n```\n\nor yarn:\n\n```bash\nyarn add --dev resolve-typescript-plugin\n```\n\n## Usage\n\nInclude the following in `package.json` to configure your project to be an ES\nModule:\n\n```json\n{\n    \"type\": \"module\"\n}\n```\n\nInclude something like the following in `webpack.config.js`:\n\n```js\nimport ResolveTypeScriptPlugin from \"resolve-typescript-plugin\";\n\nexport default {\n    module: {\n        rules: [\n            {\n                test: /\\.tsx?$/,\n                use: \"ts-loader\"\n            }\n        ]\n    },\n    resolve: {\n        plugins: [new ResolveTypeScriptPlugin()]\n    }\n};\n```\n\nYou will also need to have [ts-loader][4] (or another TypeScript loader)\ninstalled and configured.\n\nPrevious versions of this README recommended setting `resolve.fullySpecified` to\n`true`. This is no longer recommended because it breaks compatibility with\nwebpack-dev-server and possibly other webpack tooling.\n\nIf you use this plugin, you should probably remove `.ts` and `.tsx` from\n`resolve.extensions`.\n\n## Options\n\nPass options to the plugin as an argument to the constructor, as follows:\n\n```js\nnew ResolveTypeScriptPlugin({\n    includeNodeModules: false\n});\n```\n\n### includeNodeModules\n\nBy default, the plugin does not resolve TypeScript files inside `node_modules`\nsubdirectories. To enable this, set `includeNodeModules: true`.\n\nDefault: `false`.\n\n## Webpack 4 Compatibility\n\nThis plugin supports webpack versions 4.x and 5.x. However, there are some\ncaveats when using webpack 4.x in conjunction with ES modules.\n\nWebpack 4.x does not support `webpack.config` files in ES module format, so if\nyou set `\"type\": \"module\"` in `package.json` then you must mark the\n`webpack.config` file as a CommonJS file by naming it `webpack.config.cjs` (with\na `.cjs` extension). Of course, you must also use CommonJS format, for example:\n\n```js\nconst ResolveTypeScriptPlugin = require(\"resolve-typescript-plugin\");\n\nmodule.exports = {\n    module: {\n        rules: [\n            {\n                test: /\\.tsx?$/,\n                use: \"ts-loader\"\n            }\n        ]\n    },\n    resolve: {\n        plugins: [new ResolveTypeScriptPlugin()]\n    }\n};\n```\n\nWebpack 4.x also will not discover the `webpack.config` file automatically if it\nis named with a `.cjs` extension, so you must specify the path to the\nconfiguration file explicitly when running webpack, for example:\n`webpack --config ./webpack.config.cjs`.\n\nWebpack 5.x has none of these caveats. In Webpack 5.x, configuration files may\nbe in ES Module or CommonJS format, and will be discovered automatically if they\nare named with any of `.js`, `.cjs`, or `.mjs` file extensions.\n\n## Feedback\n\nPlease report bugs, problems, and missing features on the [GitHub Issue\nTracker][5].\n\n[1]: https://github.com/microsoft/TypeScript/issues/16577#issuecomment-703190339\n[2]: https://webpack.js.org/configuration/resolve/#resolveextensions\n[3]: https://github.com/TypeStrong/ts-loader/issues/1110\n[4]: https://www.npmjs.com/package/ts-loader\n[5]: https://github.com/softwareventures/resolve-typescript-plugin/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftwareventures%2Fresolve-typescript-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftwareventures%2Fresolve-typescript-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftwareventures%2Fresolve-typescript-plugin/lists"}