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

vite preview proxy config read null #6662

Closed
7 tasks done
hehehai opened this issue Jan 28, 2022 · 1 comment
Closed
7 tasks done

vite preview proxy config read null #6662

hehehai opened this issue Jan 28, 2022 · 1 comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@hehehai
Copy link

hehehai commented Jan 28, 2022

Describe the bug

script: $ vite preview --config ./vite.config.preview.ts

config file port

export default defineConfig({
  mode: 'development',
  preview: {
    host: '0.0.0.0',
    port: 4173,
    strictPort: true,
    open: true,
    proxy: {
      '/api': {
        target: 'http://localhost',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/'),
      },
    },
  },
  ......
});

Problem location

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at proxyMiddleware (/Users/guanwei/code/company/cbj_pro/cbj_app/node_modules/.pnpm/registry.npmmirror.com+vite@2.7.10_less@4.1.2/node_modules/vite/dist/node/chunks/dep-76613303.js:50062:12)
    at Object.preview (/Users/guanwei/code/company/cbj_pro/cbj_app/node_modules/.pnpm/registry.npmmirror.com+vite@2.7.10_less@4.1.2/node_modules/vite/dist/node/chunks/dep-76613303.js:73391:17)

if (config.preview.proxy) {
app.use(proxyMiddleware(httpServer, config))
}

Local dependency code

async function preview(inlineConfig) {
	......
	// proxy
    if (config.preview.proxy) {
        app.use(proxyMiddleware(httpServer, config));
    }
	......
}

export function proxyMiddleware(
httpServer: http.Server | null,
config: ResolvedConfig
): Connect.NextHandleFunction {
const options = config.server.proxy!
// lazy require only when proxy is used
const proxies: Record<string, [HttpProxy.Server, ProxyOptions]> = {}
Object.keys(options).forEach((context) => {

Local dependency code

function proxyMiddleware(httpServer, config) {
	const options = config.server.proxy;
    // lazy require only when proxy is used
    const proxies = {};
    Object.keys(options) ......
}

Judge is config.preview.proxy, but read is config.server.proxy

Reproduction

System Info

System:
    OS: macOS 12.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 5.07 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.3 - /usr/local/bin/node
    Yarn: 1.22.17 - ~/.yarn/bin/yarn
    npm: 7.24.0 - /usr/local/bin/npm
    Watchman: 2021.11.01.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 97.0.4692.99
    Firefox: 95.0.2
    Safari: 15.2
  npmPackages:
    @vitejs/plugin-vue: ^1.9.4 => 1.10.2 
    @vitejs/plugin-vue-jsx: ^1.2.0 => 1.3.3 
    vite: ^2.6.4 => 2.7.10

Used Package Manager

pnpm

Logs

❯ pnpm build
.....
success

❯ pnpm preview

> arco-design-pro-vue@1.0.0 preview /Users/guanwei/code/company/cbj_pro/cbj_app
> vite preview --config ./config/vite.config.preview.ts

error when starting preview server:
TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at proxyMiddleware (/Users/guanwei/code/company/cbj_pro/cbj_app/node_modules/.pnpm/registry.npmmirror.com+vite@2.7.10_less@4.1.2/node_modules/vite/dist/node/chunks/dep-76613303.js:50062:12)
    at Object.preview (/Users/guanwei/code/company/cbj_pro/cbj_app/node_modules/.pnpm/registry.npmmirror.com+vite@2.7.10_less@4.1.2/node_modules/vite/dist/node/chunks/dep-76613303.js:73391:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async CAC.<anonymous> (/Users/guanwei/code/company/cbj_pro/cbj_app/node_modules/.pnpm/registry.npmmirror.com+vite@2.7.10_less@4.1.2/node_modules/vite/dist/node/cli.js:782:24)
 ELIFECYCLE  Command failed with exit code 1.

Validations

@ygj6 ygj6 added has pr p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Jan 28, 2022
@bluwy
Copy link
Member

bluwy commented Apr 4, 2022

This is the same as #7414 and is fixed in #7604. Also credits to #6666 which had implemented the same fix but we had missed out on merging it.

@bluwy bluwy closed this as completed Apr 4, 2022
@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.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants