-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
Hi,
I had a lot of troubles debuging a [vite] Internal server error: undefined caused by an unvalid url using the HttpClient. The problem is more general though.
The logs are far too unprecise to help finding the piece of code at fault. The traceback is not deep enough to recover the call sequence too. Plus, async calls and the observers nature make even more hazardous the use of console.log to investigate.
In my case, I simply got such tracebacks at first :
00:48:54 [vite] Internal server error: undefined
at AbortSignal.abortHandler (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-ZONHDKL3.js:10329:14)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
at AbortSignal.dispatchEvent (node:internal/event_target:762:26)
at runAbort (node:internal/abort_controller:447:10)
at abortSignal (node:internal/abort_controller:433:3)
at AbortController.abort (node:internal/abort_controller:466:5)
at AbortSignal.abort (node:internal/deps/undici/undici:9536:14)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
at AbortSignal.dispatchEvent (node:internal/event_target:762:26)
at runAbort (node:internal/abort_controller:447:10) (x18)
TypeError [ERR_INVALID_ARG_TYPE]: The "str" argument must be of type string. Received undefined
at stripVTControlCharacters (node:internal/util/inspect:2480:3)
at prepareError (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:20391:14)
at logError (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:20422:10)
at viteErrorMiddleware (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:20427:5)
at call (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:22742:7)
at next (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:22690:5)
at call (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:22755:3)
at next (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:22690:5)
at call (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:22755:3)
at next (file:///C:/Users/Someone/WebstormProjects/my-project/node_modules/@angular/build/node_modules/vite/dist/node/chunks/dep-DbCvTk3B.js:22690:5)At some point, I did remove a catchError in my HttpClient.get(url).pipe by accident and discovered the cause of the previous error (see the missing / in input):
ERROR TypeError: Invalid URL
at new URL (node:internal/url:818:25)
at relativeUrlsTransformerInterceptorFn (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-QWZ53OKI.js:16370:18)
at eval (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-N34X6RCX.js:1434:84)
at runInInjectionContext (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-LOFXQD7Y.js:2257:12)
at eval (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-N34X6RCX.js:1434:67)
at eval (C:\Users\Someone\WebstormProjects\my-project\angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-N34X6RCX.js:1434:137)
at transferCacheInterceptorFn (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-N34X6RCX.js:2417:10)
at eval (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-N34X6RCX.js:1434:84)
at runInInjectionContext (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-LOFXQD7Y.js:2257:12)
at eval (C:\Users\Someone\WebstormProjects\my-project\.angular\cache\19.2.10\my-project\vite\deps_ssr\chunk-N34X6RCX.js:1434:67) {
code: 'ERR_INVALID_URL',
input: 'https://localhost:8000my_url',
base: 'http://localhost:4200/'
}Notice that in the case of an HttpClient, it is very common to catchError to feed with default data. Like in the following:
getData(): Observable<any[]> {
return this.httpClient.get<any[]>(this.apiUrl).pipe(
catchError(() => of(defaultData)),
shareReplay(1)
);
}Proposed solution
If you have any way of making the logs or the traceback more explicit when vite fails with Internal server error: undefined, it would be of great help !
Alternatives considered
If there is some tooling helping the debug of Vite, you may add some documentation or a blog post.