-
Notifications
You must be signed in to change notification settings - Fork 12k
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
SSG allow loading static assets #29236
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
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: