Gathering detailed insights and metrics for ts-transform-esm-import
Gathering detailed insights and metrics for ts-transform-esm-import
Gathering detailed insights and metrics for ts-transform-esm-import
Gathering detailed insights and metrics for ts-transform-esm-import
Rewrite TypeScript import paths to ES Modules import paths
npm install ts-transform-esm-import
Typescript
Module System
Node Version
NPM Version
TypeScript (94.35%)
JavaScript (4.6%)
HTML (1.05%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
12 Stars
162 Commits
3 Forks
2 Watchers
6 Branches
5 Contributors
Updated on Sep 26, 2024
Latest Version
0.11.1
Package Id
ts-transform-esm-import@0.11.1
Unpacked Size
50.07 kB
Size
13.40 kB
File Count
18
NPM Version
8.19.3
Node Version
18.13.0
Published on
Jan 26, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Rewrite TypeScript import paths to ES Modules import paths. TypeScript 4.9+!. A fork of ts-transform-import-path-rewrite.
Feature | Status | Note |
---|---|---|
Add .js extension | ✅ | |
Resolving baseUrl | ✅ | |
CommonJS main | ✅ | |
CommonJS subpath | ✅ | |
CommonJS module | ✅ | |
ESM single string entry | ✅ | |
ESM Subpath imports | ✅ | https://nodejs.org/api/packages.html#subpath-imports |
ESM Subpath patterns | ❌ | https://nodejs.org/api/packages.html#subpath-patterns |
ESM Conditional exports | ❌ | https://nodejs.org/api/packages.html#conditional-exports |
Before:
1// Files in `node_modules`. 2import 'npmModule'; 3import 'npmModule/lib'; 4 5// Files resolved by `tsconfig.baseUrl`. 6import 'subDir/file'; 7import 'rootFile'; 8 9// Relative paths. 10import './rootFile'; 11import './subDir/file';
After:
1// Files in `node_modules`. 2import '../node_modules/npmModule/dist/main.js'; 3import '../node_modules/npmModule/lib.js'; 4 5// Files resolved by `tsconfig.baseUrl`. 6import './subDir/file.js'; 7import './rootFile.js'; 8 9// Relative paths. 10import './rootFile.js'; 11import './subDir/file.js';
See example for a runnable project.
An example tsconfig.json
1{ 2 "compilerOptions": { 3 "declaration": true, 4 "newLine": "lf", 5 "strict": true, 6 "module": "ESNext", 7 "moduleResolution": "node", 8 "outDir": "./dist", 9 "baseUrl": "src", 10 "rootDir": "./src", 11 "plugins": [ 12 { 13 "transform": "ts-transform-esm-import", 14 "after": true, 15 "afterDeclarations": true, 16 "type": "config", 17 18 "rootDir": "./src", 19 "outDir": "./dist/src", 20 "resolvers": [{ "dir": "./src", "sourceDir": true }, { "dir": "./node_modules" }] 21 } 22 ] 23 } 24}
rootDir
source files root directory, should be the rootDir
in tsconfig.json
.outDir
output directory, should be the outDir
in tsconfig.json
.after
, afterDeclarations
, type
see ts-patch Options.resolvers
a list of resolvers that define how imports are transformed.
dir
: string
search location for imports.sourceDir
: boolean
whether search location contains source files (ts files).filter
: string
regex string, run resolver only when filter tests truemode
: string
overrides default resolving mode, possible values:
addExt
only adds extensions to imports.To transform imports in node_modules
:
1{ 2 "rootDir": "./src", 3 "outDir": "./dist/src", 4 "resolvers": [{ "dir": "./node_modules" }] 5}
To transform imports using TypeScript baseUrl
, set sourceDir
to true
, which indicates that we are travelling inside the source directory:
1{ 2 "rootDir": "./src", 3 "outDir": "./dist/src", 4 "resolvers": [{ "dir": "./src", "sourceDir": true }] 5}
To apply a resolver only on a subset of imports, use the filter
field (a regex value). For example, to rewrite imports starting with @myOrg/
:
1{ 2 "rootDir": "./src", 3 "outDir": "./dist/src", 4 "resolvers": [{ "dir": "./node_modules", "filter": "^@myOrg/" }] 5}
Sometimes the default resolving mode might confuse you. You can override it via the mode
field. Currently, only one option (addExt
) is supported, which simply adds a .js
extension if needed.
1{ 2 "rootDir": "./src", 3 "outDir": "./dist/src", 4 "resolvers": [{ "dir": "./node_modules", "mode": "addExt" }] 5}
You can combine multiple resolvers. For example, to do the following things altogether:
.js
extensions to all imports starting with @myOrg/
baseUrl
node_modules
Use the following config:
1{ 2 "rootDir": "./src", 3 "outDir": "./dist/src", 4 "resolvers": [ 5 { "dir": "./node_modules", "filter": "^@myOrg/", "mode": "addExt" }, 6 { "dir": "./src", "sourceDir": true }, 7 { "dir": "./node_modules" } 8 ] 9}
Make sure your module
field in tsconfig.json
is not commonjs
, esnext
is recommended.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More