CMS-of-Blog icon indicating copy to clipboard operation
CMS-of-Blog copied to clipboard

运行`npm run dev`时出现proxy error

Open leetschau opened this issue 7 years ago • 13 comments

运行npm run dev后浏览器打开URL http://localhost:8080/, 页面显示:

Error occured while trying to proxy to: localhost:8080/

Terminal中显示如下输出:

> [email protected] dev /home/leo/temp/CMS-of-Blog
> cross-env NODE_ENV=development webpack-dev-server --open --inline --hot

keywords if/then/else require v5 option
Project is running at http://localhost:8080/
webpack output is served from /dist/
404s will fallback to /index.html
[HPM] Error occurred while trying to proxy request / from localhost:8080 to http://localhost:3000/ (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
[HPM] Error occurred while trying to proxy request /favicon.ico from localhost:8080 to http://localhost:3000/ (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
Hash: 49d34f485941bceadb78
Version: webpack 2.1.0-beta.28
Time: 5002ms
                                                   Asset      Size  Chunks           Chunk Names
                 me.jpg?465872307cc7d85910962d99ca76b4cd   13.9 kB  [emitted]
                    25a32416abee198dd821b0b17a198a8f.eot   76.5 kB  [emitted]
                    d7c639084f684d66a1bc66855d193ed8.svg    392 kB  [emitted]  [big]
fontawesome-webfont.svg?0b779b31c9eef399ecd2848979788835  82 bytes  [emitted]
                  e6cf7c6ec7c2d6f670ae9d762604cb0b.woff2   71.9 kB  [emitted]
                   c8ddf1e5e5bf3682bc7bebf30f394148.woff   90.4 kB  [emitted]
                    1dc35d25e61d819a9c357074014867ab.ttf    153 kB  [emitted]
                                                 main.js   2.09 MB  0[emitted]  [big]main
                                                setup.js   1.41 MB  1[emitted]  [big]setup
                                              styles.css     17 kB  0[emitted]  main
                                               index.css   37.2 kB  0[emitted]  main
                                             favicon.ico   4.29 kB  [emitted]
                                                  me.jpg   13.9 kB  [emitted]
chunk    {0} main.js, styles.css, index.css (main) 699 kB [entry] [rendered]

...

Child extract-text-webpack-plugin:
    chunk    {0} extract-text-webpack-plugin-output-filename 44.2 kB [entry] [rendered]
        [0] ./~/css-loader/lib/css-base.js 1.51 kB {0} [built]
        [1] ./~/css-loader!./src/assets/css/font-awesome.css 39.5 kB {0} [built]
        [2] ./~/css-loader!./src/assets/css/highlight.css 1.01 kB {0} [built]
        [3] ./src/assets/fonts/fontawesome-webfont.eot 82 bytes {0} [built]
        [4] ./src/assets/fonts/fontawesome-webfont.eot?v=4.6.3 82 bytes {0} [built]
        [5] ./src/assets/fonts/fontawesome-webfont.ttf?v=4.6.3 82 bytes {0} [built]
        [6] ./src/assets/fonts/fontawesome-webfont.svg?v=4.6.3 102 bytes {0} [built]
        [7] ./src/assets/fonts/fontawesome-webfont.woff2?v=4.6.3 84 bytes {0} [built]
        [8] ./src/assets/fonts/fontawesome-webfont.woff?v=4.6.3 83 bytes {0} [built]
        [9] ./~/css-loader!./~/sass-loader!./src/style/index.scss 1.67 kB {0} [built]
[HPM] Error occurred while trying to proxy request / from localhost:8080 to http://localhost:3000/ (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
[HPM] Error occurred while trying to proxy request /favicon.ico from localhost:8080 to http://localhost:3000/ (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)

貌似proxy 8080 端口到 3000 端口这一步出错了,如何解决这个问题呢? vue.js新手,请多多指教,谢谢!

leetschau avatar Jan 08 '17 11:01 leetschau

change your proxy setting to proxy: { "/api/**": { target: "http://localhost:3000/", pathRewrite: { "^/api": "" } }

iheng avatar Jan 08 '17 20:01 iheng

@iheng webpack.config.js中proxy部分修改如下:

    proxy: {
      "/api/**": { 
          target: "http://localhost:3030/",
          pathRewrite: { "^/api": ""}
      }
    }

运行npm run dev后自动打开浏览器地址 http://localhost:8080/ ,能够显示登录页面,但输入用户名密码(都是dba)后无法登录,登录按钮部分出现如下输出:

{ "url": "/api/login", "ok": false, "status": 504, "statusText": "Gateway Timeout", "headers": { "map": { "Date": [ "Mon, 09 Jan 2017 03:05:28 GMT" ], "Connection": [ "keep-alive" ], "X-Powered-By": [ "Express" ], "Transfer-Encoding": [ "chunked" ] } }, "body": "Error occured while trying to proxy to: localhost:8080/login", "bodyBlob": {}, "bodyText": { "promise": {} } }

同时服务端显示:

[HPM] Error occurred while trying to proxy request /login from localhost:8080 to http://localhost:3030/ (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
[HPM] Error occurred while trying to proxy request /login from localhost:8080 to http://localhost:3030/ (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)

proxy还是有问题,另外端口为什么是3030,server/index.js里面不是定义的3000吗?

leetschau avatar Jan 09 '17 03:01 leetschau

@leetschau did you try change to 3000

iheng avatar Jan 09 '17 04:01 iheng

@iheng the same error after changing 3030 to 3000

leetschau avatar Jan 09 '17 06:01 leetschau

@leetschau here is steps, in your command line type step1: mongod step2: npm start step3: npm run dev the original code will work, if you follow above steps. you don't need modified the code proxy: { "/": { target: "http://localhost:3000/"

  }

or proxy: { "/api": { target: "http://localhost:3000/" } or proxy: { "/api/*": { target: "http://localhost:3000/" } if your have more question you should read wepack offical docs

iheng avatar Jan 09 '17 15:01 iheng

我也出现了这个问题,run start能跑,run dev跑不起来

BarryZhan avatar Feb 10 '17 03:02 BarryZhan

@BarryZhan @leetschau try this. it work!

  1. git clone the repository
  2. modify webpack.config.js, add proxy config
devServer: {
    historyApiFallback: true,
    noInfo: true,
    proxy: {
      '/': {
        target: 'http://localhost:3000/'
      }
    }
  }

` by the way, the ajax request did not contain '/api'

zhenizhui avatar Feb 18 '17 01:02 zhenizhui

先npm start,然后再起一个命令行npm run dev,这样8080才能代理到3000

hejingscu avatar Apr 10 '17 08:04 hejingscu

this repository contains two part: the front-end part and the back-end part; first you should "npm start" to start the back-end service; then run "npm run dev " is ok;

lisleyang avatar May 19 '17 05:05 lisleyang

为什么注册完后,跳到了登录界面,输入账号密码后点击登录,没有任何提示和跳转?

handsomeslow avatar Aug 28 '17 02:08 handsomeslow

[HPM] Error occurred while trying to proxy request /goods?page=1&pageSize=8&sort=1 from localhost:8080 to http://localhost:3000 (ENOENT) (https://nodejs.org/api/errors.html#errors_common_system_errors)

BooMiny avatar Oct 07 '17 15:10 BooMiny

when I opened the network panel I found the server responded with a status of 504 (Gateway Timeout)

userkang avatar Jul 22 '19 12:07 userkang