FaasJS
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文
Home
  • Guide
  • Documents
  • Starter Template
  • Changelog
  • Ecosystem

    • VS Code Plugin
    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
  • English
  • 简体中文

Documents / @faasjs/load / loadPackage

Function: loadPackage()

loadPackage<T>(name, defaultNames): Promise<T>

Asynchronously loads a package by its name, supporting both ESM and CommonJS runtimes.

Also supports loading TypeScript and TSX files by checking for the presence of the "tsx" package.

Type Parameters

T

T = unknown

The type of the module to be loaded.

Parameters

name

string

The name of the package to load.

defaultNames

string | string[]

Returns

Promise<T>

A promise that resolves to the loaded module.

Throws

If the runtime is unknown.

Example

const myModule = await loadPackage<MyModuleType>('my-module');