npm run dev生成UnhandledPromiseRejectionWarning

时间:2018-03-28 19:16:31

标签: javascript node.js npm vuejs2

当我在我的Vagrant机器上运行npm run dev时,我一直收到此错误UnhandledPromiseRejectionWarning,我无法弄清楚为什么或在哪里检查我的承诺在哪里完成" with catch()函数

> 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.

我的节点和npm版本是

node -v
v8.11.0
npm -v
5.6.0

这是我的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"
  ]
}

你能帮我弄清楚问题是什么或在哪里检查?如果您需要任何其他信息,请告诉我,我会提供。谢谢

**更新**

如果我在我的macos上本地运行npm run dev,代码编译正确,网页打开/工作。

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

2 个答案:

答案 0 :(得分:6)

在开发模式下opn尝试打开浏览器。当它无法在流浪汉机器上执行此操作时,它会拒绝您无法轻易捕获的承诺。添加`node.vm.network“forwarded_port”guest:80,host:8080到您的vagrantFile以允许通过主机上的端口8080访问客户端上的端口80可能会有所帮助。

答案 1 :(得分:2)

您没有使用catch函数

捕获承诺拒绝

例如:

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

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

在项目中查找这些情景。