-
Notifications
You must be signed in to change notification settings - Fork 12k
SSG allow loading static assets #29236
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
Comments
Load of assets when using SSG has been supported for some time now, Although you are required to use If the problem persists please provide a minimal runnable reproduction of the problem. You can read here why this is needed. A good way to make a minimal repro is to create a new app via |
If I set up a new app: private http = inject(HttpClient);
ngOnInit() {
this.http.get('something.json').pipe(
tap((res: any) => console.log("Success", res)),
catchError((err: any) => {
console.log("Error", err);
return of(null);
})
).subscribe();
} Indeed prints "success" However, in my app, I am using provideHttpClient(withFetch(), withInterceptorsFromDi()), But still it doesn't work: Couldn't load translation file 'assets/i18n/en.json' dt {
headers: e {
headers: Map(0) {},
normalizedNames: Map(0) {},
lazyInit: undefined,
lazyUpdate: null
},
status: 0,
statusText: 'Unknown Error',
url: 'assets/i18n/languages/en.json',
ok: false,
type: undefined,
name: 'HttpErrorResponse',
message: 'Http failure response for assets/i18n/languages/en.json: 0 undefined',
error: TypeError: Invalid URL My repository is https://github.com/sign/translate |
Hi @alan-agius4 - any ideas on this? |
…during server fetch Ensures proper handling of relative URLs to prevent errors in server-side fetch operations. Closes angular#29236
…during server fetch Ensures proper handling of relative URLs to prevent errors in server-side fetch operations. Closes #29236
@alan-agius4 Unfortuantely, after updating to the latest release, it is not yet solved. My updates: @angular-devkit/architect 0.1900.6 → 0.1900.7
@angular-devkit/build-angular 19.0.6 → 19.0.7
@angular/animations 19.0.5 → 19.0.6
@angular/cdk 19.0.4 → 19.0.5
@angular/cli 19.0.6 → 19.0.7
@angular/common 19.0.5 → 19.0.6
@angular/compiler 19.0.5 → 19.0.6
@angular/compiler-cli 19.0.5 → 19.0.6
@angular/core 19.0.5 → 19.0.6
@angular/forms 19.0.5 → 19.0.6
@angular/material 19.0.4 → 19.0.5
@angular/platform-browser 19.0.5 → 19.0.6
@angular/platform-browser-dynamic 19.0.5 → 19.0.6
@angular/platform-server 19.0.5 → 19.0.6
@angular/router 19.0.5 → 19.0.6
@angular/service-worker 19.0.5 → 19.0.6
@angular/ssr 19.0.6 → 19.0.7 Error: HttpErrorResponse {
headers: _HttpHeaders {
headers: Map(0) {},
normalizedNames: Map(0) {},
lazyInit: undefined,
lazyUpdate: null
},
status: 0,
statusText: 'Unknown Error',
url: 'assets/i18n/countries/en.json',
ok: false,
type: undefined,
name: 'HttpErrorResponse',
message: 'Http failure response for assets/i18n/countries/en.json: 0 undefined',
error: TypeError: Failed to parse URL from assets/i18n/countries/en.json
at node:internal/deps/undici/undici:12500:13
at _ZoneDelegate.invoke (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:369:28)
at ZoneImpl.run (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:111:43)
at eval (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:1221:40)
at _ZoneDelegate.invokeTask (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:402:33)
at ZoneImpl.runTask (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:159:47)
at drainMicroTaskQueue (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:581:35) {
[cause]: TypeError: Invalid URL
at new URL (node:internal/url:804:36)
at new Request (node:internal/deps/undici/undici:4839:25)
at fetch (node:internal/deps/undici/undici:9651:25)
at fetch (node:internal/deps/undici/undici:12498:10)
at fetch (node:internal/bootstrap/web/exposed-window-or-worker:79:16)
at eval (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:1472:40)
at proto.<computed> (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:913:24)
at _FetchBackend.FetchBackend.fetchImpl (/Users/amitmoryossef/dev/sign/translate/.angular/cache/19.0.7/sign-translate/vite/deps_ssr/chunk-YUNSYC3W.js:1233:41)
at eval (/Users/amitmoryossef/dev/sign/translate/.angular/cache/19.0.7/sign-translate/vite/deps_ssr/chunk-YUNSYC3W.js:1249:71)
at _ZoneDelegate.invoke (/Users/amitmoryossef/dev/sign/translate/node_modules/zone.js/fesm2015/zone-node.js:369:28) {
code: 'ERR_INVALID_URL',
input: 'assets/i18n/countries/en.json'
}
}
} |
I tried again your reproduction and I am not getting that error, I am seeing other error but these are legit as the file does not exist
|
Interesting! You are correct, about that file.
Much less critical than before, thank you! |
That is caused because I am actually surprised that you got this far without it. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Command
build
Is this a regression?
The previous version in which this bug was not present was
17
Description
I am using transloco for localization.
When building (used to be prerendering) now the build process tries to render the pages.
In doing so, it hits this loader, which loads a static asset (the language in question)
However, the HTTP request fails, since there seems to not be an http server involved in the SSG process.
If I run this in SSR, it also fails, but that is because it can't handle the path, and requires a full URL (http://localhost:4000/assets/...)
If I accept not having a server, I need to have a similar behavior to what I do during testing:
But this relies on node modules, and the builder errors:
Therefore, my issues are:
Minimal Reproduction
"prerender": true
, "ssr": {"entry": "src/server.ts"}`)src/assets
addsomething.json
AppComponent
'sngOnInit
function, makethis.httpClient.get('/assets/something.json').subscribe()
ng build --configuration=production
Exception or Error
Your Environment
Anything else relevant?
In the old prerendering, it used to work.
The text was updated successfully, but these errors were encountered: