Skip to content

Make native Node ESM support configurable #4853

Closed
@tbranyen

Description

@tbranyen

Is your feature request related to a problem or a nice-to-have?? Please describe.

Relates to: #4038

Currently unable to use "type": "module" in my mono-repo package as then Mocha runs all tests assuming native node, instead of using the configured @babel/register extensions loader. There seems to be a conflation that because a package is designated as native Node ESM, that means the tests should run that way. There is a big distinction in my case.

I import my code using the extension-less form:

import { innerHTML } from './inner-html';

(See build failure in Additional context below)

Describe the solution you'd like

I would like to see an option to be able to disable Mocha's Node interpretation, regardless of .mjs or "type": "module" in the root package.json.

Something like:

--disable-esm

Describe alternatives you've considered

  • Disabling the feature to import Node ESM from the root of my project
  • Converting all my imports to have an extension

Additional context

λ NODE_ENV=test+cov nyc -r=lcov mocha test/_setup test test/integration/*.js


Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/tim/git/diffhtml/packages/diffhtml/lib/util/types' imported from /home/tim/git/diffhtml/packages/diffhtml/lib/util/pool.js
    at finalizeResolution (internal/modules/esm/resolve.js:285:11)
    at moduleResolve (internal/modules/esm/resolve.js:708:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:798:11)
    at Loader.resolve (internal/modules/esm/loader.js:100:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)
    at link (internal/modules/esm/module_job.js:46:36)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: wontfixtypically a feature which won't be added, or a "bug" which is actually intended behaviortype: featureenhancement proposal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions