Skip to content

nyc is broken in latest nodejs versions #49653

@jeremymeng

Description

@jeremymeng

Version

v18.17.1, v20.6.1

Platform

Linux arch-hp 6.4.3-arch1-2 #1 SMP PREEMPT_DYNAMIC Sat, 15 Jul 2023 19:25:49 +0000 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

See more details in the bug report at istanbuljs/nyc#1530

nyc uses this code to transform code and compiles a module
https://github.com/istanbuljs/append-transform/blob/3e0547f68eacb10e85dbcbf1ac539df83afae751/index.js#L57-L60

In latest nodejs version (possibly with this commit 15bced0bde), it causes an error thus no transformation is done

Transformation error for /home/meng/git/nyc-repro/src/index.js ; return original code
The "mod" argument must be an instance of Module. Received an instance of Module

The information regarding the related nodejs CVE which 15bced0bde addressed seems indicating that the CVE only affect users of experimental permossion policy. I am not sure nyc is using that exprimental policy. Its last version is published a year ago. But somehow the fix to the CVE impact nyc.

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

No error. nyc should be able to transform code and produce modules like in v18.17.0. Code coverage result should be 100% with the repro

What do you see instead?

warnings then 0% code coverage result

Transformation error for /home/meng/git/nyc-repro/src/index.js ; return original code
The "mod" argument must be an instance of Module. Received an instance of Module


  basic test
    ✓ add correctly


  1 passing (3ms)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------

Additional information

Any recommendation for a fix/workaround in nyc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions