Gathering detailed insights and metrics for import-from-esm
Gathering detailed insights and metrics for import-from-esm
Gathering detailed insights and metrics for import-from-esm
Gathering detailed insights and metrics for import-from-esm
desm
get the file directory from import.meta.url
remote-esm
Import ESM from a remote endpoint
esm-loader
A ESM Loader for NodeJS and Browsers Allows to import modules from any source is extendible via modules.
@design-systems/next-esm-css
This package enables using the `esm` output from the `ds build` command in a Next.js based project. Currently Next.js doesn't allow `node_modules` to import their own CSS so using components from a `ds` based project doesn't work. [See this issue](https:/
Almost drop-in "import-from" replacement that supports loading both ESM & CJS modules
npm install import-from-esm
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (98.68%)
TypeScript (1.32%)
Total Downloads
61,922,025
Last Day
66,256
Last Week
1,386,759
Last Month
6,012,095
Last Year
49,709,733
MIT License
2 Stars
340 Commits
3 Forks
2 Watchers
17 Branches
3 Contributors
Updated on Mar 03, 2025
Latest Version
2.0.0
Package Id
import-from-esm@2.0.0
Unpacked Size
12.99 kB
Size
4.97 kB
File Count
5
NPM Version
10.9.2
Node Version
22.12.0
Published on
Dec 31, 2024
Cumulative downloads
Total Downloads
Last Day
-17%
66,256
Compared to previous day
Last Week
-9.9%
1,386,759
Compared to previous week
Last Month
5.6%
6,012,095
Compared to previous month
Last Year
307%
49,709,733
Compared to previous year
2
Import a module like with
require()
but from a given path (for ESM)
This library intends to be an almost drop-in replacement of import-from
(from which it is forked), exposing the same API and behavior but also supporting ES modules (ESM). Just add await
before importFrom
/importFrom.silent
The main benefit of using import-from
is that it abstracts the need to resolve the path and create a require
statement. Its code is really straightforward:
1(fromDirectory, moduleId) => createRequire(path.resolve(fromDirectory, "noop.js"))(moduleId);
In the case of import-from-esm
, there are a few additional benefits because of the way ESM works:
import.meta.resolve
, which is behind an experimental flag (although there's a ponyfill available at wooorm/import-meta-resolve, which import-from-esm
uses under-the-hood).require
(while the former is still in experimental).import-from-esm
re-introduces require
's file extension discovery.As you can see, there is quite a bit of complexity that is abstracted behind import-from-esm
. The first bullet point issue affected both @semantic-release/commit-analyzer
and @semantic-release/release-notes-generator
. After spending hours on research to solve the issue, I realized that the work I was doing would benefit others as well, so I decided to create a package out of it.
As a proponent of ESM, I have put a lot of thought into poly-filling require
features for import
, but finally came to the conclusion that developing a package to facilitate the ecosystem transition to ESM by reducing friction was a good thing.
$ npm install import-from-esm
1import importFrom from "import-from-esm"; 2 3// there is a file at `./foo/bar.{js,mjs,cjs,json}` 4 5await importFrom("foo", "./bar");
Like require()
, throws when the module can't be found.
Returns undefined
instead of throwing when the module can't be found.
Type: string
Directory to import from.
Type: string
What you would use in require()
.
Create a partial using a bound function if you want to import from the same fromDir
multiple times:
1const importFromFoo = importFrom.bind(null, "foo"); 2 3importFromFoo("./bar"); 4importFromFoo("./baz");
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
all dependencies are pinned
Details
Reason
update tool detected
Details
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
SAST tool is run on all commits
Details
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
project is fuzzed
Details
Reason
6 out of 6 merged PRs checked by a CI test -- score normalized to 10
Reason
project has 19 contributing companies or organizations
Details
Reason
branch protection is not maximal on development and all release branches
Details
Reason
2 existing vulnerabilities detected
Details
Reason
badge detected: InProgress
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
Found 0/26 approved changesets -- score normalized to 0
Score
Last Scanned on 2025-05-26T23:20:44Z
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