14

I have a project that's been running perfectly for a few months now, able to run npm run serve with no problem. I have to terminate and run the command again whenever I switch networks, but that has never been a problem and the server could always start again.

Until now - no matter what I do I can't get the server to start. I get this error:

npm run serve

> xbs@0.6.2 serve D:\workspace\[PROJECT]
> vue-cli-service serve

 INFO  Starting development server...
 10% building 1/1 modules 0 active ERROR  TypeError: Cannot read property 'upgrade' of undefined
TypeError: Cannot read property 'upgrade' of undefined
    at Server.<anonymous> (D:\workspace\[PROJECT]\node_modules\webpack-dev-server\lib\Server.js:667:47)
    at Array.forEach (<anonymous>)
    at new Server (D:\workspace\[PROJECT]\node_modules\webpack-dev-server\lib\Server.js:666:22)
    at serve (D:\workspace\[PROJECT]\node_modules\@vue\cli-service\lib\commands\serve.js:137:20)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

The last time I got this message was when I forgot to set the .env files, but this is a previously working copy with all necessary files set, and no changes since the last working run.

I've even tried pulling a fresh copy of the repo, running npm i and setting all env files but it still fails.

npm run lint and npm run build can still work, only npm run serve.

Am I missing anything?

kkontagion
  • 456
  • 1
  • 3
  • 12
  • That line seems related to websocket proxies – Phil Mar 26 '19 at 03:51
  • @Phil I'm lost - what do I do to fix it? – kkontagion Mar 26 '19 at 03:54
  • 1
    What's in your `vue.config.js` file? – Phil Mar 26 '19 at 04:41
  • @Phil thanks for the hints - `devServer.proxy` in my vue config was indeed trying to access a no longer existent env variable. Oddly enough this wasn't a problem for the past week or so since I removed that variable, but removing the reference to the variable solved the problem. Thanks! – kkontagion Mar 26 '19 at 06:07
  • The newest webpack-dev-server version detects this and skips the proxy target. Made a PR here https://github.com/webpack/webpack-dev-server/pull/3647 to warn the user. – Even Stensberg Aug 14 '21 at 20:09
  • In my case I forgot to even define a .env file. This can also cause " ERROR TypeError: Cannot read property 'upgrade' of undefined TypeError: Cannot read property 'upgrade' of undefined". So ".env" and vue.config.js must be checked for env variables and the env file's existence itself. – kashyap Jun 11 '23 at 05:57

6 Answers6

23

The problem was again with the .env files. My vue.config.js was trying to access a previously set environment variable that had since been removed.

Only strange thing was that there weren't any problems up til now?

kkontagion
  • 456
  • 1
  • 3
  • 12
  • 2
    I'm sure this saved me a hour of debugging. I had devServer settings in vue.config.js that messed it up for me. – Dejan.S Aug 13 '19 at 06:46
5

I guess your devServer.proxy.target is empty! You could set this configuration

yvlu wang
  • 51
  • 1
  • 2
3

For me it was that I forgot to create (or copy from another PC) the .env file after clone and try to run my project on another PC.

Sergey
  • 1,837
  • 1
  • 18
  • 22
2

I also had this problem.

I used in the project process to get the backend address(for example):

  devServer: {
    proxy: {
      '/api/back/*': {
        target: process.env.VUE_APP_BACKEND_URL,
        pathRewrite: {
          '/api/back': '/api/back',
        },
      },
    },
  },

But there was no .evn file.

Just create .env file:

VUE_APP_BACKEND_URL= 0.0.0.0:2222 #example

Didn't notice the answer @Sergey.

doox911
  • 391
  • 5
  • 18
0

I declared this environment variable in .env.dev, but the local build failed, and the same project ran without problems, so I created a new .env file and declared it in it

    proxy: {
      '/api': {
        target: process.env.VUE_APP_PROXY,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
0

this happend to me, i delete the .env =/. After create again resolve