Run the vue project locally to solve the error: TypeError: Cannot read property 'upgrade' of undefined

Reason: The environment variables used in vue.config.js are not declared in the local environment file .

1. The .env.development file (development environment file) in the project root directory :

# Base api
VUE_APP_BASE_API = '/api'
NODE_ENV = 'dev'
VUE_APP_PROXY_TARGET = 'https://xxxxxx.com'

# bim项目
VUE_APP_BASE_BIM_API='/bim-test'
VUE_APP_BIM_PROXY_TARGET = 'https://xxxxx.com'

2. vue.config.js file:

module.exports = {
    devServer: {
        ... // 省略code
        proxy: {
          // detail: https://cli.vuejs.org/config/#devserver-proxy
          [process.env.VUE_APP_BASE_API]: {
            target: process.env.VUE_APP_PROXY_TARGET,
            changeOrigin: true, // needed for virtual hosted sites
            ws: true, // proxy websockets
            pathRewrite: {
              ['^' + process.env.VUE_APP_BASE_API]: ''
            }
          },
          [process.env.VUE_APP_BASE_BIM_API]: {
            target: process.env.VUE_APP_BIM_PROXY_TARGET,
            changeOrigin: true, // needed for virtual hosted sites
            ws: true, // proxy websockets
            pathRewrite: {
              ['^' + process.env.VUE_APP_BASE_BIM_API]: ''
            }
          }
        }
      },
}

Guess you like

Origin blog.csdn.net/qq_38969618/article/details/129429413
Recommended