npm脚本会抛出错误,但不会提供任何有用的信息

时间:2018-06-07 19:58:10

标签: javascript node.js npm

尝试运行jest并查看我的测试是否通过。然而,运行jest反而给了我这个非常神秘的错误。有没有办法从节点错误消息中获取有用的内容,或者我只是无法正确读取?

0 info it worked if it ends with ok
1 verbose cli [ '/home/ec2-user/.nvm/versions/node/v10.4.0/bin/node',
1 verbose cli   '/home/ec2-user/.nvm/versions/node/v10.4.0/bin/npm',
1 verbose cli   'run',
1 verbose cli   'test' ]
2 info using npm@6.1.0
3 info using node@v10.4.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle api_rule_template@0.0.0-beta~pretest: api_rule_template@0.0.0-beta
6 info lifecycle api_rule_template@0.0.0-beta~test: api_rule_template@0.0.0-beta
7 verbose lifecycle api_rule_template@0.0.0-beta~test: unsafe-perm in lifecycle true
8 verbose lifecycle api_rule_template@0.0.0-beta~test: PATH: /home/ec2-user/.nvm/versions/node/v10.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ec2-user/environment/api_rule_template/node_modules/.bin:/home/ec2-user/.nvm/versions/node/v10.4.0/bin:/usr/local/rvm/gems/ruby-2.4.1/bin:/usr/local/rvm/gems/ruby-2.4.1@global/bin:/usr/local/rvm/rubies/ruby-2.4.1/bin:/usr/local/bin:/bin:/usr/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/opt/aws/bin:/usr/local/rvm/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
9 verbose lifecycle api_rule_template@0.0.0-beta~test: CWD: /home/ec2-user/environment/api_rule_template
10 silly lifecycle api_rule_template@0.0.0-beta~test: Args: [ '-c', 'jest' ]
11 silly lifecycle api_rule_template@0.0.0-beta~test: Returned: code: 1  signal: null
12 info lifecycle api_rule_template@0.0.0-beta~test: Failed to exec test script
13 verbose stack Error: api_rule_template@0.0.0-beta test: `jest`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/ec2-user/.nvm/versions/node/v10.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:304:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (/home/ec2-user/.nvm/versions/node/v10.4.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:961:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:5)
14 verbose pkgid api_rule_template@0.0.0-beta
15 verbose cwd /home/ec2-user/environment/api_rule_template
16 verbose Linux 4.14.33-51.37.amzn1.x86_64
17 verbose argv "/home/ec2-user/.nvm/versions/node/v10.4.0/bin/node" "/home/ec2-user/.nvm/versions/node/v10.4.0/bin/npm" "run" "test"
18 verbose node v10.4.0
19 verbose npm  v6.1.0
20 error code ELIFECYCLE
21 error errno 1
22 error api_rule_template@0.0.0-beta test: `jest`
22 error Exit status 1
23 error Failed at the api_rule_template@0.0.0-beta test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

1 个答案:

答案 0 :(得分:0)

所以答案。问题是有一个数据库连接正在尝试端口3306 for MySQL而不是使用SQLite,因为没有设置环境变量。

而不是告诉我,Jest会默默地退出,甚至从全局命令行运行jest。即使打开详细/调试也没有帮助解决这个问题。

我发现它的方法是安装expect全局包并在describeit周围编写一些包装备注。然后直接通过节点而不是通过Jest运行它显示实际错误。

我猜这是一个Jest bug。