Skip to content

vite dev server crashes when server return 502 #26192

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

Closed
1 task done
zip-fa opened this issue Nov 1, 2023 · 1 comment · Fixed by #26202
Closed
1 task done

vite dev server crashes when server return 502 #26192

zip-fa opened this issue Nov 1, 2023 · 1 comment · Fixed by #26202

Comments

@zip-fa
Copy link

zip-fa commented Nov 1, 2023

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

Hi.
My dev server crashes when HttpClient receives 502 error from backend REST api.
If you need repro - please let me know.

Minimal Reproduction

ng serve

Exception or Error

/.angular/vite-root/8255c350-0f5c-4412-a828-cfc1d8e3960e/polyfills.server.mjs:175
            throw error;
            ^
HttpErrorResponse {
  headers: HttpHeaders {
    normalizedNames: Map(13) {
      'access-control-allow-origin' => 'access-control-allow-origin',
      'cache-control' => 'cache-control',
      'cf-ray' => 'cf-ray',
      'connection' => 'connection',
      'content-length' => 'content-length',
      'content-type' => 'content-type',
      'date' => 'date',
      'expires' => 'expires',
      'nel' => 'nel',
      'referrer-policy' => 'referrer-policy',
      'report-to' => 'report-to',
      'server' => 'server',
      'x-frame-options' => 'x-frame-options'
    },
    lazyUpdate: null,
    headers: Map(13) {
      'access-control-allow-origin' => [ '*' ],
      'cache-control' => [
        'private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
      ],
      'cf-ray' => [ '81f35df6af634c80-HEL' ],
      'connection' => [ 'close' ],
      'content-length' => [ '6307' ],
      'content-type' => [ 'text/html; charset=UTF-8' ],
      'date' => [ 'Wed, 01 Nov 2023 10:13:46 GMT' ],
      'expires' => [ 'Thu, 01 Jan 1970 00:00:01 GMT' ],
      'nel' => [
        '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}'
      ],
      'referrer-policy' => [ 'same-origin' ],
      'report-to' => [
        '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/"}],"group":"cf-nel","max_age":604800}'
      ],
      'server' => [ 'cloudflare' ],
      'x-frame-options' => [ 'SAMEORIGIN' ]
    }
  },
  status: 502,
  statusText: 'Bad Gateway',
  url: 'http://127.0.0.1:4000/api/status',
  ok: false,
  name: 'HttpErrorResponse',
  message: 'Http failure response for http://127.0.0.1:4000/api/status: 502 Bad Gateway',
  error: SyntaxError: Unexpected token < in JSON at position 0
      at JSON.parse (<anonymous>)
      at FetchBackend.parseBody (file:///C:/node_modules/@angular/common/fesm2022/http.mjs:1546:50)
      at FetchBackend.doRequest (file:///C:/node_modules/@angular/common/fesm2022/http.mjs:1496:29)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}

Node.js v18.18.1

Your Environment

Angular CLI: 17.0.0-rc.3
Node: 18.18.1
Package Manager: npm 9.8.1
OS: win32 x64

Angular: 17.0.0-rc.1
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.0-rc.3
@angular-devkit/build-angular   17.0.0-rc.3
@angular-devkit/core            17.0.0-rc.3
@angular-devkit/schematics      17.0.0-rc.1
@angular/cdk                    17.0.0-next.6
@angular/cli                    17.0.0-rc.3
@angular/material               17.0.0-rc.0
@angular/ssr                    17.0.0-next.9
@schematics/angular             16.2.5
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.0

Anything else relevant?

No response

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Nov 2, 2023
…n using Vite

The commit introduces dependencies prebundling and optimisation for SSR dependencies. This is primarily needed for Angular linking and async/await downlevelling. To enable this, we need to use the undocumented `optimizeDeps` setting under the `ssr` option. This is because, the top level `optimizeDeps` vite config option  only controls browser dependencies.

For the above mentioned option to take effect and transform node packages, we also need to use `noExternal` and use a catch all `RegExp`. Note: setting this option to `true` has a different effect from a catch all `RegExp`, as the former will cause the `external` option to be ignored.

Additionally together with `externalMetadata.explicit` we add Node.js build-ins as `external`.

Closes: angular#26192
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Nov 2, 2023
…n using Vite

The commit introduces dependencies prebundling and optimisation for SSR dependencies. This is primarily needed for Angular linking and async/await downlevelling. To enable this, we need to use the undocumented `optimizeDeps` setting under the `ssr` option. This is because, the top level `optimizeDeps` vite config option  only controls browser dependencies.

For the above mentioned option to take effect and transform node packages, we also need to use `noExternal` and use a catch all `RegExp`. Note: setting this option to `true` has a different effect from a catch all `RegExp`, as the former will cause the `external` option to be ignored.

Additionally together with `externalMetadata.explicit` we add Node.js build-ins as `external`.

Closes: angular#26192
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Nov 2, 2023
…en using Vite

The commit introduces dependencies prebundling and optimisation for SSR dependencies. This is primarily needed for Angular linking and async/await downlevelling. To enable this, we need to use the undocumented `optimizeDeps` setting under the `ssr` option. This is because, the top level `optimizeDeps` vite config option  only controls browser dependencies.

For the above mentioned option to take effect and transform node packages, we also need to use `noExternal` and use a catch all `RegExp`. Note: setting this option to `true` has a different effect from a catch all `RegExp`, as the former will cause the `external` option to be ignored.

Additionally together with `externalMetadata.explicit` we add Node.js build-ins as `external`.

Closes: angular#26192
alan-agius4 added a commit that referenced this issue Nov 2, 2023
…en using Vite

The commit introduces dependencies prebundling and optimisation for SSR dependencies. This is primarily needed for Angular linking and async/await downlevelling. To enable this, we need to use the undocumented `optimizeDeps` setting under the `ssr` option. This is because, the top level `optimizeDeps` vite config option  only controls browser dependencies.

For the above mentioned option to take effect and transform node packages, we also need to use `noExternal` and use a catch all `RegExp`. Note: setting this option to `true` has a different effect from a catch all `RegExp`, as the former will cause the `external` option to be ignored.

Additionally together with `externalMetadata.explicit` we add Node.js build-ins as `external`.

Closes: #26192
alan-agius4 added a commit that referenced this issue Nov 2, 2023
…en using Vite

The commit introduces dependencies prebundling and optimisation for SSR dependencies. This is primarily needed for Angular linking and async/await downlevelling. To enable this, we need to use the undocumented `optimizeDeps` setting under the `ssr` option. This is because, the top level `optimizeDeps` vite config option  only controls browser dependencies.

For the above mentioned option to take effect and transform node packages, we also need to use `noExternal` and use a catch all `RegExp`. Note: setting this option to `true` has a different effect from a catch all `RegExp`, as the former will cause the `external` option to be ignored.

Additionally together with `externalMetadata.explicit` we add Node.js build-ins as `external`.

Closes: #26192
(cherry picked from commit 4c1265a)
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants