You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
I have an Angular v19 app that is failing within a docker build due to prerendering (even though I don't have any prerendered routes). The build succeeds when ran directly on my Windows workstation.
Minimal Reproduction
I have a really simple app configuration service/provider that exposes environment variables to the client:
constroute=Router();/** * Returns any public environment variables that start with PUBLIC_NG_ for use in the Angular app */route.get("/app-config",(req,res)=>{constconfig: Record<string,any>={};Object.keys(process.env).forEach((key)=>{if(key.startsWith("PUBLIC_NG_")){config[key]=process.env[key];}});res.json(config);});exportdefaultroute;
The Dockerfile for reference is:
# Use Node.js for building the Angular SSR app
FROM node:22 AS builder
# Set the working directory
WORKDIR /app
# Copy package.json and install dependencies
COPY package*.json ./
RUN npm ci
# Copy all files and build the Angular SSR app
COPY . .
RUN npm run build
# Use a minimal Node.js image to run the SSR server
FROM node:22-alpine AS server
# Set the working directory
WORKDIR /app
# Copy the built app from the builder stage
COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/package.json /app
# Install serve to serve the SSR app
RUN npm install -g serve
# Expose the SSR server port
EXPOSE 4000
# Command to run the SSR server
CMD ["npm", "run", "serve:ssr"]
Exception or Error
0.233 > ng build
0.233
0.541 ❯ Building...
0.944 (node:20) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
0.944 (Use `node --trace-warnings ...` to show where the warning was created)
4.862 ERROR vt {
4.862 headers: e {
4.862 headers: Map(0) {},
4.862 normalizedNames: Map(0) {},
4.862 lazyInit: undefined,
4.862 lazyUpdate: null
4.862 },
4.862 status: 0,
4.862 statusText: 'Unknown Error',
4.862 url: 'http://localhost:37773/app-config',
4.862 ok: false,
4.862 type: undefined,
4.862 name: 'HttpErrorResponse',
4.862 message: 'Http failure response for http://localhost:37773/app-config: 0 undefined',
4.862 error: TypeError: fetch failed
4.862 at node:internal/deps/undici/undici:13178:13
4.862 at a.invoke (file:///app/.angular/prerender-root/6d2a3b7b-b719-4cf2-96bb-7b6c75bc01a4/polyfills.server.mjs:3:6715)
4.862 at l.run (file:///app/.angular/prerender-root/6d2a3b7b-b719-4cf2-96bb-7b6c75bc01a4/polyfills.server.mjs:3:1985)
4.862 at file:///app/.angular/prerender-root/6d2a3b7b-b719-4cf2-96bb-7b6c75bc01a4/polyfills.server.mjs:4:576
4.862 at a.invokeTask (file:///app/.angular/prerender-root/6d2a3b7b-b719-4cf2-96bb-7b6c75bc01a4/polyfills.server.mjs:3:7341)
4.862 at l.runTask (file:///app/.angular/prerender-root/6d2a3b7b-b719-4cf2-96bb-7b6c75bc01a4/polyfills.server.mjs:3:2628)
4.862 at R (file:///app/.angular/prerender-root/6d2a3b7b-b719-4cf2-96bb-7b6c75bc01a4/polyfills.server.mjs:3:9382)
4.862 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
4.862 [cause]: Error: connect ECONNREFUSED 127.0.0.1:37773
4.862 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16) {
4.862 errno: -111,
4.862 code: 'ECONNREFUSED',
4.862 syscall: 'connect',
4.862 address: '127.0.0.1',
4.862 port: 37773
4.862 }
4.862 }
4.862 }
Can you try to replace node_modules/@angular/build/src/utils/server-rendering/launch-server.js to the below and check if the problem persists?
"use strict";/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */var__importDefault=(this&&this.__importDefault)||function(mod){return(mod&&mod.__esModule) ? mod : {"default": mod};};Object.defineProperty(exports,"__esModule",{value: true});exports.DEFAULT_URL=void0;exports.launchServer=launchServer;constnode_assert_1=__importDefault(require("node:assert"));constnode_http_1=require("node:http");constload_esm_1=require("../load-esm");constload_esm_from_memory_1=require("./load-esm-from-memory");constutils_1=require("./utils");exports.DEFAULT_URL=newURL('http://ng-localhost/');/** * Launches a server that handles local requests. * * @returns A promise that resolves to the URL of the running server. */asyncfunctionlaunchServer(){const{ reqHandler }=await(0,load_esm_from_memory_1.loadEsmModuleFromMemory)('./server.mjs');const{ createWebRequestFromNodeRequest, writeResponseToNodeResponse }=await(0,load_esm_1.loadEsmModule)('@angular/ssr/node');if(!(0,utils_1.isSsrNodeRequestHandler)(reqHandler)&&!(0,utils_1.isSsrRequestHandler)(reqHandler)){returnexports.DEFAULT_URL;}constserver=(0,node_http_1.createServer)((req,res)=>{(async()=>{// handle requestif((0,utils_1.isSsrNodeRequestHandler)(reqHandler)){awaitreqHandler(req,res,(e)=>{throwe;});}else{constwebRes=awaitreqHandler(createWebRequestFromNodeRequest(req));if(webRes){awaitwriteResponseToNodeResponse(webRes,res);}else{res.statusCode=501;res.end('Not Implemented.');}}})().catch((e)=>{res.statusCode=500;res.end('Internal Server Error.');// eslint-disable-next-line no-consoleconsole.error(e);});});server.unref();awaitnewPromise((resolve)=>server.listen(0,'127.0.0.1',resolve));constserverAddress=server.address();(0,node_assert_1.default)(serverAddress,'Server address should be defined.');(0,node_assert_1.default)(typeofserverAddress!=='string','Server address should not be a string.');returnnewURL(`http://${serverAddress.address}:${serverAddress.port}/`);}
Command
build
Is this a regression?
The previous version in which this bug was not present was
No response
Description
I have an Angular v19 app that is failing within a docker build due to prerendering (even though I don't have any prerendered routes). The build succeeds when ran directly on my Windows workstation.
Minimal Reproduction
I have a really simple app configuration service/provider that exposes environment variables to the client:
And an express route that serves back json:
The Dockerfile for reference is:
Exception or Error
Your Environment
Anything else relevant?
If I put a try/catch around the http request and suppress the error the build succeeds.
The text was updated successfully, but these errors were encountered: