Error while building: Relative import path "crypto" not prefixed with / or ./ or ../ and not in import map

I have an angular v17 project. Locally it works. The netlify site name is steady-tartufo-ac940a.netlify.app

Whenever I try to deploy it fails in the building phase with the following error:

12:38:16 AM: Netlify Build 12:38:16 AM: ──────────────────────────────────────────────────────────────── 12:38:16 AM: ​ 12:38:16 AM: ❯ Version 12:38:16 AM: @netlify/build 29.31.1 12:38:16 AM: ​ 12:38:16 AM: ❯ Flags 12:38:16 AM: baseRelDir: true 12:38:16 AM: buildId: 659b43e04ae0090007176ec1 12:38:16 AM: deployId: 659b43e04ae0090007176ec3 12:38:16 AM: ​ 12:38:16 AM: ❯ Current directory 12:38:16 AM: /opt/build/repo 12:38:16 AM: ​ 12:38:16 AM: ❯ Config file 12:38:16 AM: /opt/build/repo/netlify.toml 12:38:16 AM: ​ 12:38:16 AM: ❯ Context 12:38:16 AM: production 12:38:16 AM: ​ 12:38:16 AM: ❯ Loading plugins 12:38:16 AM: - @netlify/angular-runtime@2.0.4 from Netlify app and package.json 12:38:17 AM: ​ 12:38:17 AM: @netlify/angular-runtime (onPreBuild event) 12:38:17 AM: ──────────────────────────────────────────────────────────────── 12:38:17 AM: ​ 12:38:17 AM: ​ 12:38:17 AM: (@netlify/angular-runtime onPreBuild completed in 10ms) 12:38:17 AM: ​ 12:38:17 AM: build.command from netlify.toml 12:38:17 AM: ──────────────────────────────────────────────────────────────── 12:38:17 AM: ​ 12:38:17 AM: $ ng build 12:38:18 AM: - Building... 12:38:29 AM: ▲ [WARNING] Module "@grpc/grpc-js" used by "node_modules/@firebase/firestore/dist/index.node.mjs" is not ESM 12:38:29 AM: 12:38:29 AM: CommonJS or AMD dependencies can cause optimization bailouts. 12:38:29 AM: For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies 12:38:29 AM: 12:38:29 AM: 12:38:29 AM: ▲ [WARNING] Module "@grpc/proto-loader" used by "node_modules/@firebase/firestore/dist/index.node.mjs" is not ESM 12:38:29 AM: 12:38:29 AM: CommonJS or AMD dependencies can cause optimization bailouts. 12:38:29 AM: For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies 12:38:29 AM: 12:38:29 AM: 12:38:29 AM: ▲ [WARNING] Module "faye-websocket" used by "node_modules/@firebase/database/dist/node-esm/index.node.esm.js" is not ESM 12:38:29 AM: 12:38:29 AM: CommonJS or AMD dependencies can cause optimization bailouts. 12:38:29 AM: For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies 12:38:29 AM: 12:38:29 AM: 12:38:29 AM: ▲ [WARNING] Module "undici" used by "node_modules/@firebase/auth/dist/node-esm/index.js" is not ESM 12:38:29 AM: 12:38:29 AM: CommonJS or AMD dependencies can cause optimization bailouts. 12:38:29 AM: For more information see: https://angular.io/guide/build#configuring-commonjs-dependencies 12:38:29 AM: 12:38:29 AM: 12:38:31 AM: Prerendered 2 static routes. 12:38:31 AM: Initial Chunk Files | Names | Raw Size | Estimated Transfer Size 12:38:31 AM: main-5PP6DSN3.js | main | 705.44 kB | 182.66 kB 12:38:31 AM: polyfills-CG2UM2YX.js | polyfills | 33.96 kB | 11.03 kB 12:38:31 AM: styles-BO3QCPQ5.css | styles | 537 bytes | 537 bytes 12:38:31 AM: | Initial Total | 739.92 kB | 194.21 kB 12:38:31 AM: Application bundle generation complete. [13.368 seconds] 12:38:31 AM: ​ 12:38:31 AM: (build.command completed in 13.9s) 12:38:31 AM: ​ 12:38:31 AM: @netlify/angular-runtime (onBuild event) 12:38:31 AM: ──────────────────────────────────────────────────────────────── 12:38:31 AM: ​ 12:38:31 AM: Writing Angular SSR Edge Function ... 12:38:31 AM: ​ 12:38:31 AM: (@netlify/angular-runtime onBuild completed in 9ms) 12:38:31 AM: ​ 12:38:31 AM: Functions bundling 12:38:31 AM: ──────────────────────────────────────────────────────────────── 12:38:31 AM: ​ 12:38:31 AM: The Netlify Functions setting targets a non-existing directory: netlify/functions 12:38:31 AM: ​ 12:38:31 AM: (Functions bundling completed in 1ms) 12:38:31 AM: ​ 12:38:31 AM: Edge Functions bundling 12:38:31 AM: ──────────────────────────────────────────────────────────────── 12:38:31 AM: ​ 12:38:31 AM: Packaging Edge Functions from .netlify/edge-functions directory: 12:38:31 AM: - angular-ssr 12:38:34 AM: error: Uncaught (in promise) Error: Relative import path "crypto" not prefixed with / or ./ or ../ and not in import map from "file:///root/dist/site-wddng/server/chunk-KR75M3XF.mjs" 12:38:34 AM: const ret = new Error(getStringFromWasm0(arg0, arg1)); 12:38:34 AM: ^ 12:38:34 AM: at __wbg_new_d258248ed531ff54 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm.generated.js:443:19) 12:38:34 AM: at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm_bg.wasm:1:41320) 12:38:34 AM: at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm_bg.wasm:1:1967317) 12:38:34 AM: at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm_bg.wasm:1:2501533) 12:38:34 AM: at __wbg_adapter_40 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm.generated.js:240:8) 12:38:34 AM: at real (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm.generated.js:225:14) 12:38:34 AM: at eventLoopTick (ext:core/01_core.js:181:11) 12:38:34 AM: ​ 12:38:34 AM: Bundling of edge function failed 12:38:34 AM: ──────────────────────────────────────────────────────────────── 12:38:34 AM: ​ 12:38:34 AM: Error message 12:38:34 AM: There was an error when loading the "crypto" npm module. Support for npm modules in edge functions is an experimental feature. Refer to https://ntl.fyi/edge-functions-npm for more information. 12:38:34 AM: ​ 12:38:34 AM: Error location 12:38:34 AM: While bundling edge function 12:38:34 AM: ​ 12:38:34 AM: Resolved config 12:38:34 AM: build: 12:38:34 AM: command: ng build 12:38:34 AM: commandOrigin: config 12:38:34 AM: publish: /opt/build/repo/dist/site-wddng/browser 12:38:34 AM: publishOrigin: config 12:38:34 AM: functionsDirectory: /opt/build/repo/netlify/functions 12:38:34 AM: plugins: 12:38:34 AM: - inputs: {} 12:38:34 AM: origin: ui 12:38:34 AM: package: "@netlify/angular-runtime" 12:38:35 AM: Failed during stage "building site": Build script returned non-zero exit code: 2 12:38:35 AM: Build failed due to a user error: Build script returned non-zero exit code: 2 12:38:35 AM: Failing build: Failed to build site 12:38:35 AM: Finished processing build request in 40.617s

I have tried every forum and documentation, including the netlify AI chatbot. However I cannot solve this issue.

Hi, is there particular reason you didn’t set your base directory?

Also can you try amending your build command to ng build --prod and sharing your repo?

solved? I’m having the exact same issue, with Angular 17 as well.

Feel free to share your site name if you want help @lfarjon.