Skip to content

ES Modules broke the CLI? #199

@kemitchell

Description

@kemitchell

Invoking the CLI since 0.29.0 results in a runtime error due to the #!/usr/bin/env -S node -r esm shebang. I've reproduced the issues installing globally with npm i -g and installing in a project's node_modules for invocation via via node_modules/.bin/commonmark or npx commonmark.

Relevant Commit: 9bcf45b

I am not up-to-date on Node.js and ESM support, or this package's Node.js version compatibility contract.

I will poke around a bit now and try to see if I can introduce a test for CLI invocation.

$ node -v
v14.15.1
$ npm i -g https://github.com/commonmark/commonmark.js
# 6d80c8eedd09189f089568710dcee5c964dedb37 as of now
[...]
$ commonmark
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'esm'
Require stack:
- internal/preload
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at Module._preloadModules (internal/modules/cjs/loader.js:1217:12)
    at loadPreloadModules (internal/bootstrap/pre_execution.js:447:5)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:75:3)
    at internal/main/run_main_module.js:7:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}
$ npm i -g esm
[...]
$ commonmark
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'esm'
Require stack:
- internal/preload
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at Module._preloadModules (internal/modules/cjs/loader.js:1217:12)
    at loadPreloadModules (internal/bootstrap/pre_execution.js:447:5)
    at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:75:3)
    at internal/main/run_main_module.js:7:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions