Skip to content

🐛 Bug: "Cannot find module" if module contains TS error #5555

@sam-super

Description

@sam-super

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

When i have TS error in a module included in a test, it should show the TS error

Actual

When there is a TS error it shows "Cannot find module".

Minimal, Reproducible Example

I have what i think is a pretty simple typescript setup but at some point the compilation error handling has started causing a very hard to debug "Cannot find module", error rather than the TS error.

This is a stripped down repo which still exhibits the issue:
https://github.com/sam-super/mocha-ts-node-bug

Versions

[email protected]
[email protected]

Additional Info

E.g. from the reference example repo:

npm run test -- test/included-module-ts-error.test.ts

Exception during run: Error: Cannot find module '[...]/test/helpers/bad-module' imported from [...]/test/included-module-ts-error.test.ts

Possibly related issue is it manages to execute a test with a TS error in the top-level test file/suite without complaint:

npm run test -- test/top-level-compilation.test.ts

  should error with ts error
    ✔ but passes when it should have failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions