Skip to content

Error "Project target does not exist" While building SSR #30232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
imvikasdeep opened this issue May 2, 2025 · 3 comments
Closed
1 task

Error "Project target does not exist" While building SSR #30232

imvikasdeep opened this issue May 2, 2025 · 3 comments
Labels
needs: more info Reporter must clarify the issue

Comments

@imvikasdeep
Copy link

imvikasdeep commented May 2, 2025

Command

"build:ssr:staging": "ng build --configuration=staging && ng run my-project:server:staging",

Is this a regression?

  • 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've just upgraded from angular 13 to angular 18, Added SSR. But while running the build command it gives Project target does not exist . Here is my angular.json

Minimal Reproduction

angular.json

this is my server.ts

import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine } from '@angular/ssr';
import express from 'express';
import { fileURLToPath } from 'node:url';
import { dirname, join, resolve } from 'node:path';
import AppServerModule from './src/main.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
    const server = express();
    const serverDistFolder = dirname(fileURLToPath(import.meta.url));
    const browserDistFolder = resolve(serverDistFolder, '../browser');
    const indexHtml = join(serverDistFolder, 'index.server.html');

    const commonEngine = new CommonEngine();

    server.set('view engine', 'html');
    server.set('views', browserDistFolder);

    // Example Express Rest API endpoints
    // server.get('/api/**', (req, res) => { });
    // Serve static files from /browser
    server.get(
        '**',
        express.static(browserDistFolder, {
            maxAge: '1y',
            index: 'index.html',
        })
    );

    // All regular routes use the Angular engine
    server.get('**', (req, res, next) => {
        const { protocol, originalUrl, baseUrl, headers } = req;

        commonEngine
            .render({
                bootstrap: AppServerModule,
                documentFilePath: indexHtml,
                url: `${protocol}://${headers.host}${originalUrl}`,
                publicPath: browserDistFolder,
                providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
            })
            .then((html) => res.send(html))
            .catch((err) => next(err));
    });

    return server;
}

function run(): void {
    const port = process.env['PORT'] || 4000;

    // Start up the Node server
    const server = app();
    server.listen(port, () => {
        console.log(
            `Node Express server listening on http://localhost:${port}`
        );
    });
}

run();

Exception or Error

Project target does not exist

Your Environment

Angular CLI: 18.2.14
Node: 22.14.0
Package Manager: npm 11.3.0
OS: win32 x64

Angular: 18.2.13
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic
... platform-server, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.14
@angular-devkit/build-angular   18.2.14
@angular-devkit/core            18.2.14
@angular-devkit/schematics      18.2.14
@angular/cdk                    17.3.10
@angular/cli                    18.2.14
@angular/ssr                    18.2.14
@schematics/angular             18.2.14
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.10

Anything else relevant?

No response

@imvikasdeep imvikasdeep changed the title Error Project target does not exist While building SSR Error "Project target does not exist" While building SSR May 2, 2025
@alan-agius4
Copy link
Collaborator

What is the exact command that you are running?

@alan-agius4 alan-agius4 added the needs: more info Reporter must clarify the issue label May 2, 2025
@imvikasdeep
Copy link
Author

imvikasdeep commented May 2, 2025

this is the command

"build:ssr:staging": "ng build --configuration=staging && ng run my-project:server:staging"

npm run build:ssr:staging

@alan-agius4
Copy link
Collaborator

ng run my-project:server:staging is not longer needed with the application builder. In fact, these target was removed as part of the migration.

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: more info Reporter must clarify the issue
Projects
None yet
Development

No branches or pull requests

2 participants