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

Can No Longer Use From ESM JavaScript Actions #1208

Closed
Kurt-von-Laven opened this issue Oct 13, 2022 · 6 comments · Fixed by #1215
Closed

Can No Longer Use From ESM JavaScript Actions #1208

Kurt-von-Laven opened this issue Oct 13, 2022 · 6 comments · Fixed by #1215
Assignees
Labels
bug Something isn't working

Comments

@Kurt-von-Laven
Copy link
Contributor

Kurt-von-Laven commented Oct 13, 2022

Describe the bug

v3.0.0 was compatible with ESM, but v3.0.4 is not. See ScribeMD/docker-cache#176, which bumps the version of @actions/cache. Here is the error we encountered when attempting to upgrade:

undefined:1
require
^

ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/runner/work/docker-cache/docker-cache/dist/main/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at eval (eval at 8233 (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:146[7](https://github.com/ScribeMD/docker-cache/actions/runs/3177282360/jobs/5177539082#step:6:8)15), <anonymous>:1:1)
    at Object.[8](https://github.com/ScribeMD/docker-cache/actions/runs/3177282360/jobs/5177539082#step:6:9)233 (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:146715)
    at __nccwpck_require__ (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:683[9](https://github.com/ScribeMD/docker-cache/actions/runs/3177282360/jobs/5177539082#step:6:10)64)
    at Object.8020 (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:1:36017)
    at __nccwpck_require__ (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:683964)
    at Object.4580 (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:1:26360)
    at __nccwpck_require__ (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:683964)
    at Object.5798 (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:1:21695)
    at __nccwpck_require__ (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:683964)
    at Object.3971 (file:///home/runner/work/docker-cache/docker-cache/dist/main/index.js:202:[14](https://github.com/ScribeMD/docker-cache/actions/runs/3177282360/jobs/5177539082#step:6:15)4878)

To Reproduce
Steps to reproduce the behavior:

  1. Create a JavaScript GitHub Action that uses ESM.
  2. Attempt to import and use @actions/cache.

Expected behavior
I expected it to continue to be possible to use @actions/cache with ESM.

Additional context
Cross-filed as actions/cache#949. Not fixed at @actions/cache v3.0.5 (c.f., ScribeMD/docker-cache#207).

@Kurt-von-Laven Kurt-von-Laven added the bug Something isn't working label Oct 13, 2022
@Kurt-von-Laven
Copy link
Contributor Author

The issue was introduced at @actions/cache v3.0.2 and isn't present at v3.0.1.

@Kurt-von-Laven
Copy link
Contributor Author

I suspect the issue may be that a dependency was introduced on @azure/abort-controller without declaring it in packages/cache/package.json.

@bishal-pdMSFT
Copy link
Contributor

Hi @Kurt-von-Laven thanks for raising the PR for this. the change looks good to me but I just want to highlight that toolkit packages are using commonjs modules. I have very limited knowledge in modules, but not sure if we should really expect the ESM modules to be able to work with CJS modules seamlessly.

@Kurt-von-Laven
Copy link
Contributor Author

Kurt-von-Laven commented Oct 18, 2022

Thanks for the speedy review! Generally, ESM and CJS are intended to be interoperable in this way (with, as there always are, the occasional caveats). Indeed, I believe most of our dependencies are CJS. Now that I have found the likely cause of the crash, I wonder if this particular issue has more to do with the fact that we are using Yarn, which may forbid undeclared package imports.

@kotewar
Copy link
Contributor

kotewar commented Oct 19, 2022

Version 3.0.6 has been published. @Kurt-von-Laven can you please confirm if the issue is resolved for you?

@kotewar kotewar self-assigned this Oct 19, 2022
@Kurt-von-Laven
Copy link
Contributor Author

Awesome! Yes, it works for me in ScribeMD/docker-cache#228.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants