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

devServer.proxy do not support array type and error msg is confusing #4229

Open
lyt9304 opened this issue Jul 3, 2019 · 8 comments · May be fixed by #7320
Open

devServer.proxy do not support array type and error msg is confusing #4229

lyt9304 opened this issue Jul 3, 2019 · 8 comments · May be fixed by #7320

Comments

@lyt9304
Copy link

lyt9304 commented Jul 3, 2019

Version

3.9.0

Environment info

System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
  Binaries:
    Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.15.1/bin/npm
  Browsers:
    Chrome: 75.0.3770.100
    Firefox: 67.0
    Safari: 12.1.1
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0 
    @vue/babel-plugin-transform-vue-jsx:  1.0.0 
    @vue/babel-preset-app:  3.8.0 
    @vue/babel-preset-jsx:  1.0.0 
    @vue/babel-sugar-functional-vue:  1.0.0 
    @vue/babel-sugar-inject-h:  1.0.0 
    @vue/babel-sugar-v-model:  1.0.0 
    @vue/babel-sugar-v-on:  1.0.0 
    @vue/cli-overlay:  3.8.0 
    @vue/cli-plugin-babel: ^3.8.0 => 3.8.0 
    @vue/cli-plugin-eslint: ^3.8.0 => 3.8.0 
    @vue/cli-service: ^3.8.4 => 3.8.4 
    @vue/cli-shared-utils:  3.8.0 
    @vue/component-compiler-utils:  2.6.0 
    @vue/preload-webpack-plugin:  1.1.0 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.2.3 => 5.2.3 (4.7.1)
    vue: ^2.6.10 => 2.6.10 
    vue-eslint-parser:  6.0.4 (2.0.3, 5.0.0)
    vue-hot-reload-api:  2.3.3 
    vue-lazyload:  1.2.3 
    vue-loader:  15.7.0 
    vue-router: ^3.0.6 => 3.0.6 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.10 => 2.6.10 
    vue-template-es2015-compiler:  1.9.1 
    vuex: ^3.1.1 => 3.1.1 
  npmGlobalPackages:
    @vue/cli: 3.9.0

Steps to reproduce

// vue.config.js
module.exports = {
  devServer: {
    proxy: [
      {
        context: ['/v/api', '/v/test'],
        target: https://test.com/,
      },
    ],
  }
}

What is expected?

should work fine

What is actually happening?

vue-cli-service serve returns error and given hint:

When specified, "proxy" in package.json must be a string or an object.
Instead, the type of "proxy" was array.
Either remove "proxy" from package.json, or make it an object.

Actually we didn't write proxy in package.json, this error message makes us confusing.

@lyt9304 lyt9304 changed the title devServer.proxy do not support array type and error msg is incorrect devServer.proxy do not support array type and error msg is confusing Jul 3, 2019
@JounQin
Copy link

JounQin commented Oct 21, 2019

@sodatea Any news or workaround for this?

@JounQin
Copy link

JounQin commented Oct 21, 2019

My temporary workaround:

const config = {
  target: process.env.PROXY_TARGET || 'http://localhost:8000',
  secure: false,
  changeOrigin: true,
  logLevel: 'error',
}

const PROXY_URLS = ['api', 'media'].map(_ => '/' + _)

module.exports = PROXY_URLS.reduce(
  (proxies, url) =>
    Object.assign(proxies, {
      [url]: config,
    }),
  {},
)

@jasontianxie
Copy link

got the same error

@JounQin
Copy link

JounQin commented Dec 16, 2019

I'm glad to raise a PR for it.

@jasontianxie Did you tried my workaround mentioned above?

@michalrrcc
Copy link

I am facing the same error, I need to exclude part of the proxied context like this:

proxy: [
    {
        context: ['**', '/myapp/api/**', '!/myapp/**'],
        // ...
    },
],

@MatthewAry
Copy link

I'm facing this issue as well. @JounQin could you provide some context for your workaround? How would you fit in this fix into vue.config.js?

@MatthewAry
Copy link

MatthewAry commented Jul 31, 2020

Oh. NM I had to take a harder look at the code. Looks like you're generating the non-array representation that proxy can accept. Okay. Got it.

@mwahlhuetter
Copy link

This is still a problem in v5.0.0-rc.2
Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants