Egg: yarn run cov have issue on Windows

Created on 18 Jun 2019  ·  24Comments  ·  Source: eggjs/egg

What happens?

when use yarn run cov on windows will fail.
but npm run cov is work.

Mini Showcase Repository(REQUIRED)

npm init egg --type=simple
yarn install
yarn run cov

error on yarn

yarn run v1.16.0
$ egg-bin cov
child_process.js:114
  p.open(fd);
    ^

Error: EBADF: bad file descriptor, uv_pipe_open
    at Object._forkChild (child_process.js:114:5)
    at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:303:30)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:39:3)
    at internal/main/run_main_module.js:7:1 {
  errno: -4083,
  code: 'EBADF',
  syscall: 'uv_pipe_open'
}

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
Error: c:\Users\ausir\test\egg-yarn\node_modules\nyc\bin\nyc.js --temp-directory,./node_modules/.nyc_output,-r,text-summary,-r,json-summary,-r,json,-r,lcov,-x,example/,-x,examples/,-x,mocks**/,-x,docs/,-x,coverage/**,-x,packages/*/test/**,-x,test/**,-x,test{,-*}.js,-x,**/*{.,-}test.js,-x,**/__tests__/**,-x,**/{ava,babel,jest,nyc,rollup,webpack}.config.js,c:\Users\ausir\test\egg-yarn\node_modules\mocha\bin\_mocha,--declarations,--timeout=60000,--exit,--require=c:\Users\ausir\test\egg-yarn\node_modules\egg-bin\lib\mocha-clean.js,--require=c:\Users\ausir\test\egg-yarn\node_modules\co-mocha\lib\co-mocha.js,--require=c:\Users\ausir\test\egg-yarn\node_modules\intelli-espower-loader\intelli-espower-loader.js,test/app/controller/home.test.js exit with code 1
    at ChildProcess.<anonymous> (c:\Users\ausir\test\egg-yarn\node_modules\common-bin\lib\helper.js:56:21)
    at Object.onceWrapper (events.js:288:20)
    at ChildProcess.emit (events.js:200:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) {
  code: 1
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

success on npm

λ npm run cov

> [email protected] cov c:\Users\ausir\test\egg-yarn
> egg-bin cov



  test/app/controller/home.test.js
    √ should assert
    √ should GET /


  2 passing (2s)


=============================== Coverage summary ===============================
Statements   : 100% ( 14/14 )
Branches     : 100% ( 0/0 )
Functions    : 100% ( 3/3 )
Lines        : 100% ( 14/14 )
================================================================================

Expected behavior
same as npm run cov when use yarn run cov

Context

  • Node Version: 12.4.0
  • Egg Version: 2.15.1
  • Platform: Windows 10
maybe-bug

Most helpful comment

@atian25

之前,排查过,应该是nyc的问题。
1.npm和yarn运行到 forkNode方法的方法的时候,nyc命令和参数都相同,只有yarn会失败。我试着手动把nyc 的命令只改成 类似nyc --help一些基础命令,yarn run cov 就能正常执行,所以应该可以排除是yarn的问题。
2.如果把nyc在forkNode,执行的命令写在package. json 的scripts,使用yarn和npm,以及使用npx,都可以正常运行。

所以我也有点懵,之前那个pr就还在,还在进一步分析。

All 24 comments

yarn run cov works on my linux docker.
only error on my dev windows PC.

try node node_modules/.bin/egg-bin cov?

nope, error

λ yarn cov
yarn run v1.16.0
$ node node_modules/.bin/egg-bin cov
c:\Users\ausir\test\egg-yarn\node_modules\.bin\egg-bin:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at Module._compile (internal/modules/cjs/loader.js:718:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11
error Command failed with exit code 1.

only work on npx egg-bin cov in command line
but if I write it to package.json script then run yarn run cov
same error

λ yarn run cov
yarn run v1.16.0
$ npx egg-bin cov
child_process.js:114
  p.open(fd);
    ^

Error: EBADF: bad file descriptor, uv_pipe_open
    at Object._forkChild (child_process.js:114:5)
    at setupChildProcessIpcChannel (internal/bootstrap/pre_execution.js:303:30)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:39:3)
    at internal/main/run_main_module.js:7:1 {
  errno: -4083,
  code: 'EBADF',
  syscall: 'uv_pipe_open'
}

=============================== Coverage summary ===============================
Statements   : Unknown% ( 0/0 )
Branches     : Unknown% ( 0/0 )
Functions    : Unknown% ( 0/0 )
Lines        : Unknown% ( 0/0 )
================================================================================
Error: c:\Users\ausir\test\egg-yarn\node_modules\nyc\bin\nyc.js --temp-directory,./node_modules/.nyc_output,-r,text-summary,-r,json-summary,-r,json,-r,lcov,-x,example/,-x,examples/,-x,mocks**/,-x,docs/,-x,coverage/**,-x,packages/*/test/**,-x,test/**,-x,test{,-*}.js,-x,**/*{.,-}test.js,-x,**/__tests__/**,-x,**/{ava,babel,jest,nyc,rollup,webpack}.config.js,c:\Users\ausir\test\egg-yarn\node_modules\mocha\bin\_mocha,--declarations,--timeout=60000,--exit,--require=c:\Users\ausir\test\egg-yarn\node_modules\egg-bin\lib\mocha-clean.js,--require=c:\Users\ausir\test\egg-yarn\node_modules\co-mocha\lib\co-mocha.js,--require=c:\Users\ausir\test\egg-yarn\node_modules\intelli-espower-loader\intelli-espower-loader.js,test/app/controller/home.test.js exit with code 1
    at ChildProcess.<anonymous> (c:\Users\ausir\test\egg-yarn\node_modules\common-bin\lib\helper.js:56:21)
    at Object.onceWrapper (events.js:288:20)
    at ChildProcess.emit (events.js:200:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) {
  code: 1
}
error Command failed with exit code 1.
λ yarn cov
yarn run v1.16.0
$ node node_modules/.bin/egg-bin cov

I don't understand this log, did you exec node manually or use yarn to run?

I write node node_modules/.bin/egg-bin cov in package.json script
and execute yarn run cov

but when I execute node node_modules/.bin/egg-bin cov in command
it return same error

C:\Users\ausir\test\egg-yarn
λ node node_modules/.bin/egg-bin cov
C:\Users\ausir\test\egg-yarn\node_modules\.bin\egg-bin:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at Module._compile (internal/modules/cjs/loader.js:718:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11

it seems to be a nyc compatibility problem of windows

Hello @ausir0726. Please provide a reproducible example following the instruction.

Issues labeled by Need Reproduce will be closed if no activities in 7 days.


@ausir0726,请根据这个说明提供最小可复现代码。

如果在 7 天内没有进展会被自动关闭。

I created a video to show what different with yarn run cov and npm run cov

https://www.youtube.com/watch?v=tzS7QQkWAf8&feature=youtu.be

we need a Mini Showcase Repository, just follow the guide.

this is error repo.
https://github.com/ausir0726/egg-yarn-cov-issue

thanks for all.

thanks, I don't have any Windows, so @hyj1991 will try it tonight if he had time.

This issue is closed because it has been marked as Need Reproduce, but has not had recent activity.
If you can provide a reproduce, feel free to ping anyone of our maintainers to reopen this issue.
Thank you for your contributions.

um....? closed?

use npm instead of yarn?

yes, when use npm run cov is work.
this issue is just reported yarn run cov has the bug.
if this is not necessary, you can just close this issue.

我目前確實用 npm run cov 語法
不過因為全部的語法大多使用 yarn 所以這邊會發生不一致的語法
這邊提出 issue 只是回報 yarn 再使用這個指令有問題
而且僅會發生在 windows 的部分,會造成新手使用者使用時的疑惑
如果覺得不需要特別修復或是告知不相容 yarn 的話
就請直接關閉這個 ISSUE 吧

感謝~

windows + yarn 这个场景我们这边没用到,欢迎自行研究下看看。

从现在的报错来看,就是 yarn 调用 npm scripts,调用 egg-bin 的时候就挂了,还没到 egg 那层。

感觉是 yarn 的问题。
https://github.com/yarnpkg/yarn/issues/4059

找了一下 看起來也不像你提的
我個人沒有頭緒...
但肯定是跟於 cmd 模式下的一些衝突
我 CI 是跑 docker + yarn 所以沒有問題
本地開發 windows 採用 npm run cov
所以我暫時沒有問題
既然 ISSUE 已經開了,目前也沒有這個使用情境
我就先關起來,如果有人類似的問題查的到即可

感謝各位的努力

no idea to fix it.
I run yarn cov in linux ( docker ) is works.
when develope on windows, I change to use npm run cov

thanks for everyone.

你可以试着二分排除下,看看 egg-bin -vegg-bin test 之类的有没有问题。

从上面那个连接来看,有可能是 egg-bin 里面 fork nyc 之类的时候,在 yarn 下不知道咋了出问题了。

egg-bin 使用 yarn 只有呼叫 cov 這個指令會報錯,其他功能都是正常的
我推測是 yarn + cmd mode + cov 這個多線程用到的相依性會發生錯誤

-v

λ yarn cov
yarn run v1.16.0
$ egg-bin -v
4.13.0
Done in 1.31s.

test

λ yarn cov
yarn run v1.16.0
$ egg-bin test


  test/app/controller/home.test.js
    √ should assert
    √ should GET /


  2 passing (2s)

Done in 6.90s.

不确定,代码在 https://github.com/eggjs/egg-bin/blob/master/lib/cmd/cov.js

也可能是 cov 的时候,代码被 nyc 转译了,你可以试试把 egg-bin 调用 nyc 的命令,拿出来直接放到 npm scripts 去看看

有明確的語法可以協助測試嗎?
看不是很明白...

https://github.com/eggjs/egg-bin/blob/master/lib/cmd/cov.js#L90

可以看下 nodejs fork 相关文档。

@atian25

之前,排查过,应该是nyc的问题。
1.npm和yarn运行到 forkNode方法的方法的时候,nyc命令和参数都相同,只有yarn会失败。我试着手动把nyc 的命令只改成 类似nyc --help一些基础命令,yarn run cov 就能正常执行,所以应该可以排除是yarn的问题。
2.如果把nyc在forkNode,执行的命令写在package. json 的scripts,使用yarn和npm,以及使用npx,都可以正常运行。

所以我也有点懵,之前那个pr就还在,还在进一步分析。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

XadillaX picture XadillaX  ·  44Comments

fengmk2 picture fengmk2  ·  44Comments

Yao-JSON picture Yao-JSON  ·  34Comments

jtyjty99999 picture jtyjty99999  ·  52Comments

itsky365 picture itsky365  ·  62Comments