loopbackio / loopbackio/loopback-next

Latest loopback mocha tests are not running

Open
#9,561 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug Testlab
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

### Describe the bug

Create a new lb app with node 16,
Trying to run the default tests that come with lb app, using yarn test, it immediately throws this typescript error. This seems to be a mocha issue, but why did Loopback upgrade to latest mocha?

ERR_REQUIRE_ESM errors with Mocha tests.

```
const stringWidth = require('string-width');
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/fahad/work/testapp/node_modules/string-width/index.js from /home/fahad/work/testapp/node_modules/yargs/node_modules/cliui/build/index.cjs not supported.
Instead change the require of index.js in /home/fahad/work/testapp/node_modules/yargs/node_modules/cliui/build/index.cjs to a dynamic import() which is available in all CommonJS modules.
at Object. (/home/fahad/work/testapp/node_modules/yargs/node_modules/cliui/build/index.cjs:291:21)
at Object. (/home/fahad/work/testapp/node_modules/yargs/build/index.cjs:2861:12)
at Object. (/home/fahad/work/testapp/node_modules/yargs/yargs:3:69)
at Object. (/home/fahad/work/testapp/node_modules/mocha/lib/cli/cli.js:15:15)
at Object. (/home/fahad/work/testapp/node_modules/mocha/bin/mocha.js:141:3) {
code: 'ERR_REQUIRE_ESM'
}
```

### Logs

_No response_

### Additional information

If I downgrade `yargs` library to 14.2.2, this issue is not occurring.

### Reproduction

THIS ISSUE IS OBVIOUS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run yarn test in a newly created LoopBack app using Node 16 and inspect the generated test setup and dependency versions around Mocha and yargs. Done means the default Mocha tests run without the reported ERR_REQUIRE_ESM failure while retaining the intended dependency versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.