Skip to content

AppHosting startCommand & framework port limitation #9884

@FranRiadigos

Description

@FranRiadigos

// Angular and nextjs CLIs allow for specifying port options but the emulator is setting and
// specifying specific ports rather than use framework defaults or w/e the user has set, so we
// need to reject such custom commands.
// NOTE: this is not robust, a command could be a wrapper around another command and we cannot
// detect --port there.
if (startCommand.includes("--port") || startCommand.includes(" -p ")) {
throw new FirebaseError(
"Specifying a port in the start command is not supported by the apphosting emulator",
);
}
// Angular does not respect the NodeJS.ProcessEnv.PORT set below. Port needs to be
// set directly in the CLI.
if (startCommand.includes("ng serve")) {
startCommand += ` --port ${port}`;
}

We just upgraded from 14.10.x and the emulator stopped working.

The logic prevents that we use --port in the command, which is too restrictive, specially taking into account that the option is called startCommand and allows any arbitrary command.
Further on that logic, it adds the port only if the command contains ng serve, which is Angular only, and it makes no sense, since it can easily be a call to a custom script.

In my opinion, this isn't a good approach, unless you want to reduce flexibility, which in that case I wouldn't even provide a custom startCommand at all.

I recommend that either

  • you remove this limitation and document the user should pass the port manually in the start command (as we were doing already in our team)
  • or you pass an arbitrary -- --port $port no matter the command that is set up by the user and document that option too

This change was introduced in 14.17.0, but I believe this should have been flagged as a breaking change. Unfortunately, nothing was warned or documented either.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    emulator: app hostingIssues related to the App Hosting emulator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions