angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Angular v16 esbuild ignores base href

Open adumitrescu-plenty opened this issue 2 years ago • 3 comments

Command

serve

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

We have an application that uses a development environment inside docker container. For this we are using 'allowed hosts serve' options in which we specify our urls. We have a base href present in our intex.html. This works fine with browser builder. But when we try using 'browser-esbuild' it's not working anymore. All of the chunk files get 503 error including the @vite/client and .angular/cache/vite altho main.js, pollyfills.js and scripts.js load successfully.

Minimal Reproduction

This can be reproduced with a development environment inside docker container including our configuration from the description (a custom url inside 'allowed hosts' <e.g. 'my.custom.url'> and a base href <e.g. '/ui/foo' >). After the build is successful, navigate to the url my.custom.url/ui/foo and in the console you will see my.custom.url/chunk-123.js gets 503 error.

Exception or Error

No response

Your Environment

Angular CLI: 16.1.3
Node: 16.14.0
Package Manager: npm 9.7.2
OS: darwin x64

Angular: 16.1.3
... animations, cdk, cdk-experimental, cli, common, compiler
... compiler-cli, core, forms, language-service, material
... material-experimental, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                          Version
----------------------------------------------------------
@angular-devkit/architect        0.1601.3
@angular-devkit/build-angular    16.1.3
@angular-devkit/core             16.1.3
@angular-devkit/schematics       16.1.3
@angular-devkit/schematics-cli   16.1.3
@schematics/angular              16.1.3
ng-packagr                       16.1.0
rxjs                             7.8.1
typescript                       4.9.5

Anything else relevant?

No response

adumitrescu-plenty avatar Jul 24 '23 13:07 adumitrescu-plenty

esbuild is such frustration. to deal with. i wish i didnt migrate my project. :(

d9j avatar Oct 04 '23 03:10 d9j

Same problem, the chunk file try to be loaded from the root. base href not considered !

Djay77 avatar Dec 06 '23 15:12 Djay77

I have the same issue when using the router with withHashLocation(). I am using @angular-devkit/build-angular 17.1.0-next.2

Danyyer avatar Dec 15 '23 12:12 Danyyer

Workaround for a single slash is to set the "serverPath" in the options "baseHref": "/some-app" ... "options": { "proxyConfig": "proxy.json", "servePath": "/" }

https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/build_angular/src/builders/dev-server/vite-server.ts#L86

However this doesn't work for two slashes "baseHref": "/apps/some-app"

conalryan avatar Feb 15 '24 13:02 conalryan

Thanks for reporting this issue. Luckily, it has already been fixed in one of the recent releases. Please update to the most recent version to resolve the problem.

If the problem persists in your application after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. You can use ng new repro-app to create a new project where you reproduce the problem.

alan-agius4 avatar Mar 05 '24 12:03 alan-agius4

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.