Imports for TypeScript modules for Edge Functions are different because of the Deno runtime environment
Netlify Edge Functions use Deno as the runtime, so you’ll follow Deno standards for importing/exporting files
.ts
file extension at the end of your filename. For example ./person.ts
. File extensions are required when importing modules. All your imported files should have file extensions for their own imports too.1// Netlify Function
2import Person, { sayHello } from "../someDir/person.ts";
1// ../someDir/person.ts
2import { randomFoo } from "./foo.ts"; // nested imports need to have file extensions too
3
4export const sayHello
5export default Person
Otherwise you will get similar to the following error:
TypeError: Module not found "file:///media/Files/foo/netlify/edge-functions/constants".
If you’re trying to import another file in the edge functions directory, that file needs to be an edge function module, i.e. it should return a function. If you just want to have a basic TS file, for example for saving constant strings, move it outside the edge functions directory
1// file: netlify/edge-functions/weather.ts
2import { OWM_API_KEY, OWM_BASE_URL } from "../../constants.ts"
1// file: src/constants.ts
2export const OWM_API_KEY = Netlify.env.get("OPENWEATHER_API_KEY")
3export const OWM_BASE_URL = `https://api.openweathermap.org/data/2.5/weather`
Otherwise you will get similar to the following error:
◈ Failed to load Edge Function constants. The file does not seem to have a function as the default export.