Unable to Deploy Edge-Function

Netlify Site Name: https://sagarin-matchup.netlify.app/

Description: I’m trying to deploy a site that uses an edge function. The edge function imports and calls a function from another directory in the repository. Locally things run fine. However, the build/bundling step fails with the following error:

7:39:10 AM: Packaging Edge Functions from edge-function directory:
7:39:10 AM:  - api
7:39:11 AM: error: Uncaught (in promise) Error: Module not found "file:///app/main.ts".
7:39:11 AM:       const ret = new Error(getStringFromWasm0(arg0, arg1));

I’ve specifically chosen to use edge-functions because the primary business logic was written with the Deno runtime.

The repository directory structure example:

/app - main application code
/website
  /edge-function
    api.js - imports main.ts from app directory
  /src - source code for astro project. 
  netlify.toml

netlify.toml

[build]
    edge_functions = "edge-function"
    base = "website"

[dev]
    port = 8888
    targetPort = 3000
    autoLaunch = false

[[edge_functions]]
    path = "/api"
    function = "api"

Full error log

7:38:29 AM: Waiting for other deploys from your team to complete. Check the queue: https://app.netlify.com/teams/shea-uqrfh6q/builds
7:38:50 AM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
7:38:50 AM: build-image tag: v4.14.3
7:38:50 AM: buildbot version: 4f669c94b322d52f143cdcbb17e55d40094aa06d
7:38:50 AM: Fetching cached dependencies
7:38:50 AM: Starting to download cache of 264.6KB
7:38:50 AM: Finished downloading cache in 37.572245ms
7:38:50 AM: Starting to extract cache
7:38:50 AM: Finished extracting cache in 5.736912ms
7:38:50 AM: Finished fetching cache in 85.165082ms
7:38:50 AM: Starting to prepare the repo for build
7:38:50 AM: Preparing Git Reference pull/1/head
7:38:51 AM: Parsing package.json dependencies
7:38:52 AM: Different build dir detected, going to use the one specified in the Netlify configuration file: 'website' versus '' in the Netlify UI
7:38:52 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'website' versus '' in the Netlify UI
7:38:52 AM: Section completed: initializing
7:38:52 AM: Starting build script
7:38:52 AM: Installing dependencies
7:38:52 AM: Python version set to 2.7
7:38:53 AM: Downloading and installing node v16.18.1...
7:38:53 AM: Downloading https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz...
7:38:53 AM: Computing checksum with sha256sum
7:38:53 AM: Checksums matched!
7:38:55 AM: Now using node v16.18.1 (npm v8.19.2)
7:38:55 AM: Enabling node corepack
7:38:56 AM: Started restoring cached build plugins
7:38:56 AM: Finished restoring cached build plugins
7:38:56 AM: Attempting ruby version 2.7.2, read from environment
7:38:57 AM: Using ruby version 2.7.2
7:38:57 AM: Using PHP version 8.0
7:38:57 AM: No npm workspaces detected
7:38:57 AM: Started restoring cached node modules
7:38:57 AM: Finished restoring cached node modules
7:38:57 AM: Installing NPM modules using NPM version 8.19.2
7:39:03 AM: added 453 packages, and audited 454 packages in 5s
7:39:03 AM: 189 packages are looking for funding
7:39:03 AM:   run `npm fund` for details
7:39:03 AM: found 0 vulnerabilities
7:39:03 AM: NPM modules installed
7:39:03 AM: Creating package sha
7:39:03 AM: Started restoring cached go cache
7:39:03 AM: Finished restoring cached go cache
7:39:03 AM: Installing Go version 1.17 (requested 1.17)
7:39:08 AM: unset GOOS;
7:39:08 AM: unset GOARCH;
7:39:08 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
7:39:08 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
7:39:08 AM: go version >&2;
7:39:08 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
7:39:08 AM: go version go1.17 linux/amd64
7:39:08 AM: Detected 1 framework(s)
7:39:08 AM: "astro" at version "1.6.3"
7:39:08 AM: Installing missing commands
7:39:08 AM: Verify run directory
7:39:10 AM: ​
7:39:10 AM: ────────────────────────────────────────────────────────────────
7:39:10 AM:   Netlify Build                                                 
7:39:10 AM: ────────────────────────────────────────────────────────────────
7:39:10 AM: ​
7:39:10 AM: ❯ Version
7:39:10 AM:   @netlify/build 28.1.13
7:39:10 AM: ​
7:39:10 AM: ❯ Flags
7:39:10 AM:   baseRelDir: true
7:39:10 AM:   buildId: 6378dc55f87b3400088a8ca6
7:39:10 AM:   deployId: 6378dc55f87b3400088a8ca8
7:39:10 AM: ​
7:39:10 AM: ❯ Current directory
7:39:10 AM:   /opt/build/repo/website
7:39:10 AM: ​
7:39:10 AM: ❯ Config file
7:39:10 AM:   /opt/build/repo/website/netlify.toml
7:39:10 AM: ​
7:39:10 AM: ❯ Context
7:39:10 AM:   deploy-preview
7:39:10 AM: ​
7:39:10 AM: ────────────────────────────────────────────────────────────────
7:39:10 AM:   1. Edge Functions bundling                                    
7:39:10 AM: ────────────────────────────────────────────────────────────────
7:39:10 AM: ​
7:39:10 AM: Packaging Edge Functions from edge-function directory:
7:39:10 AM:  - api
7:39:11 AM: error: Uncaught (in promise) Error: Module not found "file:///app/main.ts".
7:39:11 AM:       const ret = new Error(getStringFromWasm0(arg0, arg1));
7:39:11 AM:                   ^
7:39:11 AM:     at __wbg_new_651776e932b7e9c7 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js:313:19)
7:39:11 AM:     at <anonymous> (wasm://wasm/00a90a36:1:78732)
7:39:11 AM:     at <anonymous> (wasm://wasm/00a90a36:1:1463894)
7:39:11 AM:     at <anonymous> (wasm://wasm/00a90a36:1:1957066)
7:39:11 AM:     at __wbg_adapter_18 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js:144:6)
7:39:11 AM:     at real (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js:128:14)
7:39:11 AM: ​
7:39:11 AM: ────────────────────────────────────────────────────────────────
7:39:11 AM:   Bundling of edge function failed                              
7:39:11 AM: ────────────────────────────────────────────────────────────────
7:39:11 AM: ​
7:39:11 AM:   Error message
7:39:11 AM:   Command failed with exit code 1: deno run --allow-all --no-config --quiet --import-map=/opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/import_map.json /opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/bundle.ts {"basePath":"/opt/build/repo/website","destPath":"/tmp/edge-6378dc55f87b3400088a8ca8/e7a3c673-0c36-4f1b-a890-7f60b1b63352.eszip","functions":[{"name":"api","path":"/opt/build/repo/website/edge-function/api.js"}],"importMapURL":"data:application/json;base64,eyJpbXBvcnRzIjp7Im5ldGxpZnk6ZWRnZSI6Imh0dHBzOi8vZWRnZS5uZXRsaWZ5LmNvbS92MS9pbmRleC50cyJ9fQ=="} (https://ntl.fyi/exit-code-1)
7:39:11 AM:   error: Uncaught (in promise) Error: Module not found "file:///app/main.ts".
7:39:11 AM:         const ret = new Error(getStringFromWasm0(arg0, arg1));
7:39:11 AM:                     ^
7:39:11 AM:       at __wbg_new_651776e932b7e9c7 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js:313:19)
7:39:11 AM:       at <anonymous> (wasm://wasm/00a90a36:1:78732)
7:39:11 AM:       at <anonymous> (wasm://wasm/00a90a36:1:1463894)
7:39:11 AM:       at <anonymous> (wasm://wasm/00a90a36:1:1957066)
7:39:11 AM:       at __wbg_adapter_18 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js:144:6)
7:39:11 AM:       at real (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm.generated.js:128:14)
7:39:11 AM: ​
7:39:11 AM:   Error location
7:39:11 AM:   While bundling edge function
7:39:12 AM: Creating deploy upload records
7:39:11 AM: ​
7:39:11 AM:   Resolved config
7:39:11 AM:   build:
7:39:11 AM:     base: /opt/build/repo/website
7:39:11 AM:     edge_functions: /opt/build/repo/website/edge-function
7:39:12 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
7:39:11 AM:     environment:
7:39:11 AM:       - REVIEW_ID
7:39:11 AM:     publish: /opt/build/repo/website
7:39:11 AM:     publishOrigin: default
7:39:11 AM: Caching artifacts
7:39:11 AM: Started saving node modules
7:39:11 AM: Finished saving node modules
7:39:11 AM: Started saving build plugins
7:39:11 AM: Finished saving build plugins
7:39:11 AM: Started saving pip cache
7:39:11 AM: Finished saving pip cache
7:39:11 AM: Started saving emacs cask dependencies
7:39:11 AM: Finished saving emacs cask dependencies
7:39:11 AM: Started saving maven dependencies
7:39:11 AM: Finished saving maven dependencies
7:39:11 AM: Started saving boot dependencies
7:39:11 AM: Finished saving boot dependencies
7:39:11 AM: Started saving rust rustup cache
7:39:11 AM: Finished saving rust rustup cache
7:39:11 AM: Started saving go dependencies
7:39:11 AM: Finished saving go dependencies
7:39:12 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:39:12 AM: Failing build: Failed to build site
7:39:12 AM: Finished processing build request in 22.637772304s

Would it be possible for you to share a repo as a reproduction?

The repo can be found here: https://github.com/sleslein/sagarin-matchup.

use the website branch

Hey @sleslein,

The problem is that, when you set a base folder, Netlify is then no longer able to access files in its parent directory.

Thus, when you set website as the base directory, Netlify cannot access the root folder, and you have the app/main.ts inside the root folder. This is why, it fails.

The solution would be to either:

  1. Move the app/main.ts to anywhere inside website directory
  2. OR remove the base from netlify.toml. However, this would cause other issues, to solve those, you would have to move your package.json (from website directory) to the root directory as well.