如何使用节点js和babel保留正确的行号

时间:2016-03-26 12:35:34

标签: javascript node.js babeljs

我有以下设置并且我的错误/堆栈跟踪有问题我错过了什么?

package.json看起来像是:

{
  "name": "xxxxxx",
  "main": "server.js",
  "private": true,
  "scripts": {
    "start": "nodemon --exec ./node_modules/.bin/babel-node server.js"
  },
  "dependencies": {
    "babel": "^6.5.2",
    "babel-cli": "^6.6.5",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "babel-preset-stage-0": "^6.5.0",
    "babel-runtime": "^6.6.1"
  }
}

.babelrc看起来像:

{
  presets: ["es2015", "stage-0", "react"],
  sourceMap: 'inline',
  retainLines: true
}

server.js看起来像是:

let aVar = '';

throw new Error('some error');
import errorHandler from './app/middlewares/error_handler';

我的堆栈跟踪很疯狂

module.js:341
    throw err;
    ^
Error: Cannot find module 'bugsnag'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/projectName/lib/util/error.js:14:113)
    at Module._compile (module.js:413:34)
    at loader (/home/projectName/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/projectName/node_modules/babel-register/lib/node.js:136:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/projectName/app/middlewares/error_handler.js:11:91)
    at Module._compile (module.js:413:34)
    at loader (/home/projectName/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/home/projectName/node_modules/babel-register/lib/node.js:136:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/home/projectName/server.js:15:22)
    at Module._compile (module.js:413:34)

正如您所看到的,这看起来并不正确,而且很难遵循。我相信有办法解决这个问题。

1 个答案:

答案 0 :(得分:0)

看起来你错过了&#39; bugsnag&#39;模块。 尝试:

npm install -g bugsnag