简体   繁体   中英

npm run dev produces UnhandledPromiseRejectionWarning

I keep getting this error UnhandledPromiseRejectionWarning when I run npm run dev on my Vagrant machine and I can't figure out why or where to check where my promise ins't "completed" with catch() function

> Listening at http://localhost:8080

(node:5839) UnhandledPromiseRejectionWarning: Error: Exited with code 3
    at ChildProcess.cp.once.code (/home/vagrant/workspace/my-app/node_modules/opn/index.js:84:13)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:567:12)
(node:5839) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5839) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My node and npm versions are

node -v
v8.11.0
npm -v
5.6.0

This is my package.json

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "myapp",
  "author": "myapp@myapp.com",
  "private": true,
  "scripts": {
    "dev": "node build/dev-server.js",
    "start": "npm run dev",
    "build": "node build/build.js"
  },
  "dependencies": {
    "ajv": "^6.4.0",
    "axios": "^0.17.1",
    "jquery": "^3.3.1",
    "jsvat": "^1.2.3",
    "jwt-payload-decoder": "^1.2.4",
    "vee-validate": "^2.0.6",
    "vue": "^2.5.16",
    "vue-axios": "^2.1.0",
    "vue-cookie": "^1.1.4",
    "vue-easy-slider": "^3.2.0",
    "vue-flash": "^2.1.2",
    "vue-localstorage": "^0.6.2",
    "vue-router": "^3.0.1",
    "vue-vimeo-player": "0.0.6",
    "vue2-google-maps": "^0.8.11",
    "vuejs-jwt": "^1.0.0",
    "vuejs-paginate": "^1.8.0"
  },
  "devDependencies": {
    "autoprefixer": "^7.2.6",
    "babel-core": "^6.22.1",
    "babel-loader": "^7.1.4",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "babel-register": "^6.22.0",
    "chalk": "^2.3.2",
    "connect-history-api-fallback": "^1.5.0",
    "copy-webpack-plugin": "^4.5.1",
    "css-loader": "^0.28.11",
    "eventsource-polyfill": "^0.9.6",
    "express": "^4.16.3",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.11",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "http-proxy-middleware": "^0.17.3",
    "opn": "^5.3.0",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.4.0",
    "portfinder": "^1.0.13",
    "rimraf": "^2.6.0",
    "semver": "^5.5.0",
    "shelljs": "^0.7.6",
    "uglifyjs-webpack-plugin": "^1.2.4",
    "url-loader": "^0.5.8",
    "vue-loader": "^13.7.1",
    "vue-style-loader": "^3.1.2",
    "vue-template-compiler": "^2.5.16",
    "webpack": "^3.11.0",
    "webpack-bundle-analyzer": "^2.11.1",
    "webpack-dev-middleware": "^1.12.2",
    "webpack-hot-middleware": "^2.21.2",
    "webpack-merge": "^4.1.2"
  },
  "engines": {
    "node": ">= 4.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]
}

Can you please help me figure out what is the problem or where to check? If you need any additional informations, please let me know and I will provide. Thank you

** UPDATE **

If I run npm run dev locally on my macos, code compiles properly and web page is open/working.

npm --version
5.5.1
node --version
v8.9.2

In Dev mode opn tries to open a browser. When it can't do this on the vagrant machine it rejects a promise, which you can't easily catch. Adding `node.vm.network "forwarded_port" guest: 80, host: 8080 to your vagrantFile to allow access to port 80 on the guest via port 8080 on the host might help.

You're not catching a promise rejection using the function catch :

For example:

function().then(p => logic); 
                           ^
                           |
//Here you need to call the function 'catch' as follow:

function().then(p => logic).catch(err => handle that error)

Find in your project those scenarios.

Same error but with "Exited with code: 1" for any person who might have came here with the same problem as me.

I encountered this error because I had reverted to a really old version of node (6.17.1) for another project . updating to a recent node version (16.13.1) fixed this issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM