Skip to Content
FunctionsUse Trusted ESM in a Function
On this page

Use Trusted ESM in a Function

Trusted ESM lets a MiniUp Function use static HTTPS imports from approved sources. Use it when a small library provides useful functionality such as geometry helpers or data transformations.

Add an approved import

  1. Open Functions → your Function → Code and review the Trusted ESM sources shown in the editor.
  2. Choose a browser-compatible ESM module from an approved HTTPS source. Pin an explicit version for predictable behavior.
  3. Add a static import at the top of the Function code.
  4. Run Test with a request that exercises the imported functionality.
  5. Publish after the preview succeeds and test the live endpoint.

Example using an approved geometry helper

Use this import only when https://esm.sh/ appears in the editor’s approved list.

import { point } from "https://esm.sh/@turf/helpers@7.2.0"; export default { async fetch(request) { if (request.method !== "POST") { return Response.json({ error: "Use POST" }, { status: 405 }); } let input; try { input = await request.json(); } catch { return Response.json({ error: "Invalid JSON" }, { status: 400 }); } const { lng, lat } = input; if (!Number.isFinite(lng) || !Number.isFinite(lat) || Math.abs(lng) > 180 || Math.abs(lat) > 90) { return Response.json({ error: "Valid lng and lat required" }, { status: 400 }); } return Response.json(point([lng, lat])); } };

Test with POST and body {"lng":-97.74,"lat":30.27}. Enable POST in the Function’s allowed methods.

Understand dependency behavior

Imports are resolved during Test/Preview and Publish. Production execution does not need to fetch each imported dependency from a third-party source on every request. There is no npm install or package.json workflow for a MiniUp Function.

The approved list can change. Unsupported sources, unsupported import forms, incompatible modules, or dependency limits should produce a test/publish error. Resolve the error before publishing; do not assume every package available on an approved source can run in a Function. MiniUp shows the approved sources; ordinary Function users do not configure the global source policy.

Trusted ESM · HTTPS import · dependency · library · Turf