dineshsonachalam/markdown-autodocs

Error [ERR_REQUIRE_ESM]: require()

Closed this issue · 4 comments

I tried to configure this awesome github action on the github repo for cloudgrep and got the following error.

I tried a simple gha based on the provided example:

Nothing fancy just trying out this action.

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/markdown-autodocs/node_modules/@technote-space/doctoc/dist/index.mjs not supported.

I have just one section that I wanted to generate:

<!-- MARKDOWN-AUTO-DOCS:START (JSON_TO_HTML_TABLE:src=./pkg/provider/aws/zz_integration_stats.json) -->
<!-- MARKDOWN-AUTO-DOCS:END -->

The issue is that this github action does not initialize properly, here is more info:

Run python3 action.py -repo 'run-x/cloudgrep' -access_token '***' -commit_author 'RemyDeWolf <RemyDeWolf@users.noreply.github.com>' -commit_user_email 'actions@github.com' -commit_message 'Update resource lists' -branch 'refs/heads/remy/generate-list-supported-resources' -output_file_paths '[./README.md]' -categories '[code-block,json-to-html-table,workflow-artifact-table,markdown]'
  python3 action.py -repo 'run-x/cloudgrep' -access_token '***' -commit_author 'RemyDeWolf <RemyDeWolf@users.noreply.github.com>' -commit_user_email 'actions@github.com' -commit_message 'Update resource lists' -branch 'refs/heads/remy/generate-list-supported-resources' -output_file_paths '[./README.md]' -categories '[code-block,json-to-html-table,workflow-artifact-table,markdown]'
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
added 193 packages, and audited 194 packages in 9s
68 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/markdown-autodocs/node_modules/@technote-space/doctoc/dist/index.mjs not supported.
Instead change the require of /usr/local/lib/node_modules/markdown-autodocs/node_modules/@technote-space/doctoc/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/usr/local/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/lib/transforms/toc.js:1:23)
    at Object.<anonymous> (/usr/local/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/lib/transforms/index.js:4:13)
    at Object.<anonymous> (/usr/local/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/lib/processFile.js:5:20)
    at Object.<anonymous> (/usr/local/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/index.js:2:21)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}
On branch remy/generate-list-supported-resources
Your branch is up to date with 'origin/remy/generate-list-supported-resources'.

https://github.com/run-x/cloudgrep/runs/7098589642?check_suite_focus=true

I also tried on my local laptop and got the same error

 npm i -g markdown-autodocs

added 193 packages, and audited 194 packages in 6s

68 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
markdown-autodocs --help
node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /opt/homebrew/lib/node_modules/markdown-autodocs/node_modules/@technote-space/doctoc/dist/index.mjs not supported.
Instead change the require of /opt/homebrew/lib/node_modules/markdown-autodocs/node_modules/@technote-space/doctoc/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/lib/transforms/toc.js:1:23)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/lib/transforms/index.js:4:13)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/lib/processFile.js:5:20)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/markdown-autodocs/node_modules/markdown-magic/index.js:2:21)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.0.0

Let me know if you have any additional questions. I am not familiar with node so I'm sorry that I was not able to troubleshoot more. Hopefully this will ring a bell and this is a simple one.
Remy

I did a bit of investigation on this and I believe this is not a wide issue. It looks like we have this issue because we have another npm project in our repo under ./fe and when installing the github action markdown-autodocs they overlap.
I would say that installing markdown-autodocs should not depend if there is another npm project in the current repo but there might be some complexity that I don't understand with npm.
For us, this is indeed preventing us to use markdown-autodocs.

Feel free to close if you think this is not worth fixing.

I was getting this same error when using markdown-autodocs in a repo without any npm projects. I think the problem is caused by a recent upgrade of the doctoc package to an ES Module and I was able to fix it by downgrading to doctoc@2.1.0.

My workflow file now looks like the following:

- name: Setup Node.js environment
  uses: actions/setup-node@v3.3.0
- name: Downgrade doctoc version
  run: |
    npm install -g doctoc@2.1.0
- name: Markdown autodocs
  uses: dineshsonachalam/markdown-autodocs@v1.0.4

@tdepke2 thank you for the workaround - I confirmed that it fixes the issue.