Initial commit - Event Planner application
This commit is contained in:
21
node_modules/load-esm/LICENSE.txt
generated
vendored
Normal file
21
node_modules/load-esm/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright © 2025 Borewit
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
140
node_modules/load-esm/README.md
generated
vendored
Normal file
140
node_modules/load-esm/README.md
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
[](https://github.com/Borewit/load-esm/actions/workflows/nodejs-ci.yml)
|
||||
[](https://npmjs.org/package/load-esm)
|
||||
[](https://npmcharts.com/compare/load-esm?start=365)
|
||||
|
||||
# load-esm
|
||||
|
||||
**load-esm** is a tiny utility that lets CommonJS (CJS) TypeScript projects **dynamically import pure ESM packages** at runtime—without hacks like `eval()`.
|
||||
|
||||
It helps avoid errors like:
|
||||
|
||||
* `Error [ERR_REQUIRE_ESM]: require() of ES Module`
|
||||
* `Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in ...`
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install load-esm
|
||||
# or
|
||||
yarn add load-esm
|
||||
# or
|
||||
pnpm add load-esm
|
||||
```
|
||||
|
||||
> Works in CJS TypeScript projects. No config changes required.
|
||||
|
||||
---
|
||||
|
||||
## Quick start
|
||||
|
||||
```ts
|
||||
// TypeScript (CJS project)
|
||||
import { loadEsm } from "load-esm";
|
||||
|
||||
(async () => {
|
||||
const esmModule = await loadEsm("esm-module");
|
||||
// use esmModule...
|
||||
})();
|
||||
```
|
||||
|
||||
### With typings
|
||||
|
||||
```ts
|
||||
import { loadEsm } from "load-esm";
|
||||
|
||||
(async () => {
|
||||
const esmModule = await loadEsm<typeof import("esm-module")>("esm-module");
|
||||
// esmModule is fully typed
|
||||
})();
|
||||
```
|
||||
|
||||
### Concrete example (pure ESM package)
|
||||
|
||||
```ts
|
||||
import { loadEsm } from "load-esm";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// Import a pure ESM package from a CommonJS TS project
|
||||
const { fileTypeFromFile } = await loadEsm<typeof import("file-type")>(
|
||||
"file-type"
|
||||
);
|
||||
|
||||
const type = await fileTypeFromFile("fixture.gif");
|
||||
console.log(type);
|
||||
} catch (error) {
|
||||
console.error("Error importing module:", error);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
> Note: Because top‑level `await` isn’t available in CommonJS, examples use an async IIFE.
|
||||
|
||||
---
|
||||
|
||||
## API
|
||||
|
||||
```ts
|
||||
function loadEsm<T = unknown>(name: string): Promise<T>
|
||||
```
|
||||
|
||||
**Parameters**
|
||||
|
||||
* `name` — Package name or file path to import.
|
||||
|
||||
**Returns**
|
||||
|
||||
* `Promise<T>` resolving to the imported module namespace.
|
||||
|
||||
---
|
||||
|
||||
## How it works
|
||||
|
||||
In CJS TypeScript projects (`"module": "commonjs"`), the TS compiler transpiles dynamic `import()` to `require()`, which **breaks** when the target is a pure ESM package.
|
||||
|
||||
`load-esm` executes the `import()` **outside of TypeScript’s transpilation scope**, preserving native dynamic `import()` semantics at runtime. This keeps your code type‑safe while avoiding brittle workarounds (e.g., wrapping `import()` in `eval()`).
|
||||
|
||||
### What about Node.js ≥ 22.12?
|
||||
|
||||
Since Node.js 22.12, `require` can load **some** ESM modules, but there are [documented constraints](https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require). If your dependencies are compatible with that path, you might not need this utility. `load-esm` remains useful when:
|
||||
|
||||
* You’re on older Node.js versions that support `import()` (see Compatibility) but not the newer `require()` behavior.
|
||||
* You want a single, consistent pattern that works across environments and avoids edge cases.
|
||||
|
||||
> If Node’s built‑in `require(esm)` works for your packages and version, feel free to use it.
|
||||
|
||||
---
|
||||
|
||||
## Compatibility
|
||||
|
||||
* **Node.js**: ≥ 13.2.0 (first version with native `import()` support)
|
||||
* **TypeScript**: Fully typed; works in CJS projects.
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
* **`ERR_REQUIRE_ESM`**: Ensure you’re using `load-esm(...)` to import the ESM dependency from CJS code.
|
||||
* **`No "exports" main defined`**: Some packages only expose ESM entry points. Import them via `load-esm`.
|
||||
* **Type declarations**: Use the generic form `loadEsm<typeof import("pkg")>("pkg")` for typed access.
|
||||
* **Top‑level await**: Wrap usage in an async IIFE in CJS.
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE.txt)
|
||||
|
||||
---
|
||||
|
||||
### Changelog
|
||||
|
||||
See [Releases](https://github.com/Borewit/load-esm/releases).
|
||||
|
||||
---
|
||||
|
||||
### Acknowledgements
|
||||
|
||||
Inspired by common pain points when mixing CJS projects with modern ESM‑only libraries.
|
||||
1
node_modules/load-esm/index.d.ts
generated
vendored
Normal file
1
node_modules/load-esm/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export function loadEsm<T = any>(name: string): Promise<T>;
|
||||
3
node_modules/load-esm/index.js
generated
vendored
Normal file
3
node_modules/load-esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
loadEsm: (module) => import(module)
|
||||
};
|
||||
76
node_modules/load-esm/package.json
generated
vendored
Normal file
76
node_modules/load-esm/package.json
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "load-esm",
|
||||
"version": "1.0.3",
|
||||
"type": "commonjs",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"compile-test": "tsc -p test"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"author": {
|
||||
"name": "Borewit",
|
||||
"url": "https://github.com/Borewit"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/Borewit"
|
||||
},
|
||||
{
|
||||
"type": "buymeacoffee",
|
||||
"url": "https://buymeacoffee.com/borewit"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"description": "Utility to dynamically load ESM modules in TypeScript CommonJS projects",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/Borewit/load-esm.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/Borewit/load-esm/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Borewit/load-esm#readme",
|
||||
"keywords": [
|
||||
"load-esm",
|
||||
"ESM",
|
||||
"Import ESM",
|
||||
"CJS",
|
||||
"CommonJS",
|
||||
"TypeScript",
|
||||
"Node.js",
|
||||
"dynamic import",
|
||||
"dynamic module loading",
|
||||
"dynamic load",
|
||||
"JavaScript modules",
|
||||
"CJS ESM interoperability",
|
||||
"import ESM in CommonJS",
|
||||
"typescript commonjs import esm",
|
||||
"module interoperability",
|
||||
"node esm loader",
|
||||
"mixed module",
|
||||
"dynamic esm import typescript",
|
||||
"cjs to esm bridge",
|
||||
"ERR_REQUIRE_ESM",
|
||||
"require ESM error",
|
||||
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
||||
"No \"exports\" main defined in",
|
||||
"exports not defined error"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=13.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^5.0.1",
|
||||
"@types/mocha": "^10.0.10",
|
||||
"@types/node": "^22.10.2",
|
||||
"chai": "^4.3.4",
|
||||
"mocha": "^11.0.1",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user