Skip to content

Misleading ERR_REQUIRE_CYCLE_MODULE when attempting to import from module if module was never installed #5290

@MaxKessler5

Description

@MaxKessler5

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

I forgot to npm install a library, and tried to test with Mocha. I expected an error about the missing module.

Actual

The error claims the missing module is a cyclical import. It is not cyclical, it is just missing

Minimal, Reproducible Example

Here is a gist that reproduces the problem using bash: https://gist.github.com/MaxKessler5/9d53a143df67ce1cd4dff9e9f03d2db4

The contents:

npm init -y
sed -i 's/"type": "commonjs"/"type": "module"/' package.json
echo "// Entry point for the application" > index.js
echo "import { cloneDeep } from "lodash-es";" >> index.js
sed -i 's/"test":.*/"test": "mocha"/' package.json
npm install mocha
mkdir test
echo "import "../index.js";" > test/test.js
npm test > output.txt

Versions

$ npx mocha --version
11.1.0

node_modules/.bin/mocha --version
(I'm on windows, not sure how to do this one)

node --version
v22.12.0

Additional Info

No response

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