Skip to content
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

preview.proxy does not work when server.proxy is empty #7414

Closed
7 tasks done
liuyang678 opened this issue Mar 23, 2022 · 2 comments · Fixed by #7604
Closed
7 tasks done

preview.proxy does not work when server.proxy is empty #7414

liuyang678 opened this issue Mar 23, 2022 · 2 comments · Fixed by #7604

Comments

@liuyang678
Copy link

liuyang678 commented Mar 23, 2022

Describe the bug

Configuring preview.proxy doesn't work, and running vite preview will give an error when server.proxy is not configured.

image

pr: #7415

Reproduction

https://stackblitz.com/edit/vitejs-vite-b5medm?file=vite.config.ts&terminal=dev

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
    Memory: 17.19 GB / 24.88 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.17 - /mnt/d/Programs/nodejs/yarn
  npmPackages:
    vite: ^2.8.0 => 2.8.6

Used Package Manager

yarn

Logs

> vite preview

error when starting preview server:
TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at proxyMiddleware (/Users/liuyang/Desktop/work/yiyao_fe_shangjia_react/b2c_welcome/node_modules/vite/dist/node/chunks/dep-9c153816.js:51440:12)
    at preview (/Users/liuyang/Desktop/work/yiyao_fe_shangjia_react/b2c_welcome/node_modules/vite/dist/node/chunks/dep-9c153816.js:69529:17)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async CAC.<anonymous> (/Users/liuyang/Desktop/work/yiyao_fe_shangjia_react/b2c_welcome/node_modules/vite/dist/node/cli.js:783:24)

Validations

@liuyang678 liuyang678 changed the title preview.proxy not work preview.proxy does not work when server.proxy is empty Mar 28, 2022
@gao-zhan
Copy link

I have the same problem, can anyone help me

@Jinjiang
Copy link
Contributor

Jinjiang commented Apr 3, 2022

I met the same problem. Then I digged a little bit and found:

The current process: first detect whether config.preview.proxy exists:

if (config.preview.proxy) {

second read config.server.proxy to proceed:

const options = config.server.proxy!

which leads a bug when users preview with config.preview.proxy but without config.server.proxy.

To fix this, I'm afraid this part of code needs a little revamp since the middleware doesn't differentiate which mode it's under.

Hope this information is helpful.

Thanks.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants