[BUG] Fails to load `.../formatter.js` when project `type: module`
mastermel opened this issue · 3 comments
Is there an existing issue for this?
- I have searched the existing issues
Does this issue exist in the latest version?
- I'm using the latest release
Describe the bug?
Since version 8.1 this action fails to run in projects where "type": "module"
is present in the package.json
with the following error/output:
There was a problem loading formatter: /home/runner/work/eslint-changed-files-test/eslint-changed-files-test/formatter.js
Error: require() of ES Module /home/runner/work/eslint-changed-files-test/eslint-changed-files-test/formatter.js from /home/runner/work/eslint-changed-files-test/eslint-changed-files-test/node_modules/eslint/lib/cli-engine/cli-engine.js not supported.
formatter.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename formatter.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/runner/work/eslint-changed-files-test/eslint-changed-files-test/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
I've only tested this in Typescript+React projects using the latest version of all available dependencies. To help reproduce I've created this bare-minimum sample repo with two PRs. The first PR is using v8 of this shared action and it works correctly, meaning it runs eslint on the changed file and reports the issue. The second PR is using v8.5 (latest as of writing) and fails to run eslint, instead giving the above error.
I'd be happy to offer any other info or try different things if I can. I don't think that I can make my actual projects work without "type": "module"
so I'm hoping there's a fix or config change I can make to get that playing nicely with the latest releases of your wonderful GH Action 🙇
To Reproduce
- In a Typescript project leveraging the latest version of Node.js 16, Eslint, and tj-actions/esling-changed-files being leveraged in a GH Workflow running on PR. (see sample here)
- Add
"type": "module"
topackage.json
- Create a pull request containing a change that violates the configured Eslint rules
- Notice that the automatic check fails to run eslint
What OS are you seeing the problem on?
ubuntu-latest or ubuntu-20.04
Expected behavior?
I expect eslint to be run on the changed files and issues reported on the PR as usual. (see working example)
Relevant log output
See output from GH Workflow run here:
https://github.com/mastermel/eslint-changed-files-test/runs/4810291379?check_suite_focus=true
Anything else?
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Thanks for reporting this issue.
@mastermel This should be resolved in the latest release v8.6.