question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible Bug with mocha new configuration file

See original GitHub issue

Hi, I need help with an issue with mocha new configuration file. I apologize if I am going through the wrong avenue for help. Anyways my .mocharc.js file is in the root directory of my project and its content is

'use strict';

module.exports = {
  require: ['ts-node/register', 'esm'],
  file: ['./test/testSetup.ts'],
  reporter: 'nyan',
  ui: 'bdd',
};

when i run the cli mocha "./test/**/*.spec.tsx" I get an unexpected token export in one of my node_modules dependencies

when I specify explicitly through the cli mocha -r ts-node/register -r esm --file "./test/testSetup.ts" --ui bdd "./test/**/*.spec.tsx" it is able to run the test just fine

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
flinders-coreycommented, Aug 7, 2019

Hi,

I had a similar issue to this happen to me earlier today.

Using version 6.1.4 I was able to use mocha with esm with the following sections in my package.json file:

"scripts": {
  "test": "mocha"
},
"mocha": {
  "require": [
    "esm"
  ],
  "recursive": true
}

Post upgrade to mocha 6.2.0 this did not work. The esm module wasn’t being called. I was getting the dreaded SyntaxError: Unexpected token { error for my import statement.

I needed to change my package.json file so that esm was explicitly called via the command line. For example:

"scripts": {
  "test": "mocha --require esm"
},
"mocha": {
  "require": [
    "esm"
  ],
  "recursive": true
}

I’m not sure if these two issues are related or not. As I found this thread via a Google search to work out what was wrong, I thought it worth mentioning.

1reaction
flinders-coreycommented, Aug 13, 2019

@juergba I can confirm that with the patch applied as per #3983 my use case works. Specifically using the following in my package.json file.

"scripts": {
  "test": "mocha"
},
"mocha": {
  "require": [
    "esm"
  ],
  "recursive": true
}

My thanks to you and the team for working on this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mochajs/mocha - Gitter
Hello all! I have been running around SO, mocha source, issues, and any other tutorials I can find, but I am still doing...
Read more >
FAQ - MochaSoft
After installation, use menu - tools - configuration to import/export the users configuration file. You can run tn5250.exe or tn3270.exe with the configuration ......
Read more >
Why is Mocha not working with Yarn Berry? - Stack Overflow
If a bug you should open an issue on our repository (Yarn). However, Mocha is covered by an E2E test and a bug...
Read more >
Mocha documentation — DevDocs
New in v6.0.0. Specify an explicit path to a package.json file (ostensibly containing configuration in a mocha property). By ...
Read more >
mocha - UNPKG
13, ## :bug: Fixes. 14. 15, - [#4668](https://github.com/mochajs/mocha/issues/4668): ESM: make `--require <dir>` work with new `import`-first loading ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found