Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocha 6.2.0 gives error "Cannot find module esm" #4002

Closed
4 tasks done
ebdrup opened this issue Aug 27, 2019 · 2 comments
Closed
4 tasks done

Mocha 6.2.0 gives error "Cannot find module esm" #4002

ebdrup opened this issue Aug 27, 2019 · 2 comments
Labels
duplicate been there, done that, got the t-shirt...

Comments

@ebdrup
Copy link

ebdrup commented Aug 27, 2019

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • '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, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

When using esmmocha 6.2.0 gives the error Cannot find module esm, if I change nothing and run the same thing in mocha 6.1.4 everything works.

Steps to Reproduce

.mocharc.js

module.exports = {
  require: ['esm', './test/common.js'],
  recursive: true,
  timeout: 10000,
  exit: true,
  spec: './test/**/*.test.js',
  package: './package.json',
};

test/common.js

import cnf from 'cnf';
import 'chai/register-should';
import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiSubset from 'chai-subset';

chai.use(chaiHttp);
chai.use(chaiSubset);

Expected behavior: [What you expect to happen]

Test run

Actual behavior: [What actually happens]

Output

> NODE_ENV=test mocha

mocha debug [spec..]

Run tests with Mocha

Rules & Behavior
  --allow-uncaught           Allow uncaught errors to propagate        [boolean]
  --async-only, -A           Require all tests to use a callback (async) or
                             return a Promise                          [boolean]
  --bail, -b                 Abort ("bail") after first test failure   [boolean]
  --check-leaks              Check for global variable leaks           [boolean]
  --delay                    Delay initial execution of root suite     [boolean]
  --exit                     Force Mocha to quit after tests complete  [boolean]
  --forbid-only              Fail if exclusive test(s) encountered     [boolean]
  --forbid-pending           Fail if pending test(s) encountered       [boolean]
  --global, --globals        List of allowed global variables            [array]
  --retries                  Retry failed tests this many times         [number]
  --slow, -s                 Specify "slow" test threshold (in milliseconds)
                                                          [string] [default: 75]
  --timeout, -t, --timeouts  Specify test timeout threshold (in milliseconds)
                                                        [string] [default: 2000]
  --ui, -u                   Specify user interface    [string] [default: "bdd"]

Reporting & Output
  --color, -c, --colors                     Force-enable color output  [boolean]
  --diff                                    Show diff on failure
                                                       [boolean] [default: true]
  --full-trace                              Display full stack traces  [boolean]
  --growl, -G                               Enable Growl notifications [boolean]
  --inline-diffs                            Display actual/expected differences
                                            inline within each string  [boolean]
  --reporter, -R                            Specify reporter to use
                                                      [string] [default: "spec"]
  --reporter-option, --reporter-options,    Reporter-specific options
  -O                                        (<k=v,[k1=v1,..]>)           [array]

Configuration
  --config   Path to config file           [string] [default: (nearest rc file)]
  --opts     Path to `mocha.opts`        [string] [default: "./test/mocha.opts"]
  --package  Path to package.json for config                            [string]

File Handling
  --extension, --watch-extensions  File extension(s) to load and/or watch
                                                           [array] [default: js]
  --file                           Specify file(s) to be loaded prior to root
                                   suite execution     [array] [default: (none)]
  --ignore, --exclude              Ignore file(s) or glob pattern(s)
                                                       [array] [default: (none)]
  --recursive                      Look for tests in subdirectories    [boolean]
  --require, -r                    Require module      [array] [default: (none)]
  --sort, -S                       Sort test files                     [boolean]
  --watch, -w                      Watch files in the current working directory
                                   for changes                         [boolean]

Test Filters
  --fgrep, -f   Only run tests containing this string                   [string]
  --grep, -g    Only run tests matching this string or regexp           [string]
  --invert, -i  Inverts --grep and --fgrep matches                     [boolean]

Positional Arguments
  spec  One or more files, directories, or globs to test
                                                     [array] [default: ["test"]]

Other Options
  --help, -h     Show usage information & exit                         [boolean]
  --version, -V  Show version number & exit                            [boolean]
  --interfaces   List built-in user interfaces & exit                  [boolean]
  --reporters    List built-in reporters & exit                        [boolean]

✖ ERROR: Unexpected identifier
npm ERR! Test failed.  See above for more details.

Reproduces how often:
100%

Versions

  • The output of mocha --version
    ash: /usr/local/bin/mocha: No such file or directory

and node node_modules/.bin/mocha --version:
6.2.0

  • The output of node --version:
    v10.16.3

  • Your operating system

    • name and version:
      macOS Mojave, version 10.14.6

    • architecture (32 or 64-bit):
      64

  • Your shell (e.g., bash, zsh, PowerShell, cmd):
    standard OSX

  • Your browser and version (if running browser tests):

  • Any third-party Mocha-related modules (and their versions):

    "chai": "4.2.0",
    "chai-http": "4.3.0",
    "chai-subset": "1.6.0",

  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version):
    esm v3.2.25

Additional info:

If you globally install mocha ant try to run tests it gives the error Cannot find module esm

@juergba
Copy link
Member

juergba commented Aug 27, 2019

I suppose you have been installing the esm package.
duplicate see #3975

@juergba juergba added duplicate been there, done that, got the t-shirt... and removed unconfirmed-bug labels Sep 1, 2019
@juergba juergba closed this as completed Sep 1, 2019
@FossPrime
Copy link

FossPrime commented May 7, 2021

The solutions to this are here: sveltejs/kit#612 (comment)

Tl;dr;

  • use an experimental extension resolving feature OR
  • Change your extensions and add index.js to all your directory auto resolutions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate been there, done that, got the t-shirt...
Projects
None yet
Development

No branches or pull requests

3 participants