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

Github Javascript Action requiring ESLint throws Cannot find module '@eslint/eslintrc/universal' #14986

Closed
AriPerkkio opened this issue Aug 28, 2021 · 9 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects

Comments

@AriPerkkio
Copy link
Contributor

AriPerkkio commented Aug 28, 2021

Relates to third party integrations with ESLint utilizing nodejs linter API.

Tell us about your environment

  • ESLint Version: 8.0.0-beta.0
  • Node Version: 14.17.5
  • npm Version: Not sure, but it's the one provided by Github CI
  • Operating System: Ubuntu / Github CI. Locally Debian 10.

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using?

Unrelevant, but default.

Please show your full configuration:

Unrelevant, but:

Configuration
{ root: true }

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

Requiring eslint with absolute path fails due to @eslint/eslintrc/universal being unable to load.

} = require("@eslint/eslintrc/universal"), // eslint-disable-line node/no-missing-require -- false positive

I'm only able to reproduce this issue in Github CI. In local environment it always works. I have no idea why.

const pkgPath = path.resolve('./node_modules/eslint');
console.log(`Running require('${pkgPath}')`);
require(pkgPath);
Running require('/home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint')
Cannot find module '@eslint/eslintrc/universal'
Require stack:
- /home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/lib/linter/linter.js
- /home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/lib/linter/index.js
- /home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/lib/cli-engine/cli-engine.js
- /home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/lib/eslint/eslint.js
- /home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/lib/eslint/index.js
- /home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/lib/api.js
- /home/runner/work/_actions/AriPerkkio/eslint-remote-tester-run-action/test/eslint-v8/dist/index.js

https://github.com/AriPerkkio/eslint-remote-tester-bot-test-setups/runs/3449285821?check_suite_focus=true

This error message is also mentioned in different issue: #14936 (comment).

What did you expect to happen?

Should work exactly as v7 works.
This issue only comes up with v8 beta. Eslint@7 works fine.

What actually happened? Please copy-paste the actual, raw output from ESLint.

eslint/lib/linter/linter.js fails to load.

Steps to reproduce this issue:

Sorry for not being able to provide easy repro but I'll try to describe the situtation.

Run this file in Github CI https://github.com/AriPerkkio/eslint-remote-tester-run-action/blob/acb6f063cb0d9ea8dfd183e69caba14dd7a67330/dist/index.js.

In minimal repro:
eslint-remote-tester-run-acton imports eslint using absolute path. This is how Github CI Action can utilize dependencies of projects it is being used in. https://github.com/AriPerkkio/eslint-remote-tester-run-action/blob/acb6f063cb0d9ea8dfd183e69caba14dd7a67330/dist/index.js#L24-L27

In my real use case:

  1. Npm package eslint-remote-tester utilizes ESLint's Nodejs API: engine/worker-task.ts
  2. Github CI action eslint-remote-tester-run-action is requring eslint-remote-tester using absolute path: peer-dependencies.ts.
  3. Dependency chain: eslint-remote-tester-run-action -> eslint-remote-tester -> eslint -> @eslint/eslintrc/universal

Are you willing to submit a pull request to fix this bug?

Yes.

Some debugging narrowing common mistakes out of scope

https://github.com/AriPerkkio/eslint-remote-tester-bot-test-setups/runs/3449285821?check_suite_focus=true

  1. ./node_modules/@eslint/eslintrc/dist and its universal is available on file system ✅
> ls ./node_modules/@eslint/eslintrc/dist

eslintrc-universal.cjs
eslintrc-universal.cjs.map
eslintrc.cjs
eslintrc.cjs.map 
  1. eslint@8 is available on file system ✅
Running require('/home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/eslint/package.json')
{
  name: 'eslint',
  version: '8.0.0-beta.0',
  ...
  1. @eslint/eslintrc@1 is available on file system ✅
Running require('/home/runner/work/eslint-remote-tester-bot-test-setups/eslint-remote-tester-bot-test-setups/node_modules/@eslint/eslintrc/package.json')
{
  name: '@eslint/eslintrc',
  version: '1.0.0',
  description: 'The legacy ESLintRC config file format for ESLint',
  type: 'module',
  main: './dist/eslintrc.cjs',
  exports: {
    '.': { import: './lib/index.js', require: './dist/eslintrc.cjs' },
    './package.json': './package.json',
    './universal': {
      import: './lib/index-universal.js',
      require: './dist/eslintrc-universal.cjs'
    }
...
@AriPerkkio AriPerkkio added bug ESLint is working incorrectly repro:needed labels Aug 28, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Aug 28, 2021
@dimaMachina
Copy link

I think this will help you #14936 (comment)

@AriPerkkio
Copy link
Contributor Author

Thanks but this setup doesn't have jest. It is a simple nodejs require call.

@mdjermanovic
Copy link
Member

Run this file in Github CI https://github.com/AriPerkkio/eslint-remote-tester-run-action/blob/acb6f063cb0d9ea8dfd183e69caba14dd7a67330/dist/index.js.

I couldn't reproduce this error in Github CI with a copy of the file, only with the action.

This works (runs local file): https://github.com/mdjermanovic/test-eslint-beta/blob/main/.github/workflows/smoke-test.yml
This doesn't (runs action): https://github.com/mdjermanovic/test-eslint-beta/blob/main/.github/workflows/smoke-test-uses-action.yml

Could it be that the action is run using a different Node.js version that doesn't support subpaths in "exports"?

Can you add this to the test action:

console.log(process.version);

@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Aug 28, 2021
@mdjermanovic
Copy link
Member

Looks like it's v12.13.1, which isn't supported by ESLint v8.

https://github.com/mdjermanovic/test-eslint-beta/runs/3451676360?check_suite_focus=true

@mdjermanovic
Copy link
Member

It will probably work well in a node:16 container.

Here's a test action: https://github.com/mdjermanovic/test-docker-action

Test run: https://github.com/mdjermanovic/test-eslint-beta/runs/3452043609?check_suite_focus=true

@AriPerkkio AriPerkkio changed the title require('./node_modules/eslint') throws Cannot find module '@eslint/eslintrc/universal' Github Javascript Action requiring ESLint throws Cannot find module '@eslint/eslintrc/universal' Aug 29, 2021
@AriPerkkio
Copy link
Contributor Author

AriPerkkio commented Aug 29, 2021

That's it - great catch @mdjermanovic! The workflow is running node 14.17.5 but the action is running node 12.13.1.

I was blindly trusting the workflow logs when actions/setup-node@v2 printed node/14.17.5. The Github Javascript actions seem to run in "container/isolated environment" with their own nodejs.

> Run actions/setup-node@v2
Found in cache @ /opt/hostedtoolcache/node/14.17.5/x64

> Run AriPerkkio/eslint-remote-tester-run-action@test/eslint-v8
console.log(process.version);
'v12.13.1'

Currently node14 seems to be unavailable in Javascript actions:

runs:
  using: 'node14'
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter ''using: node14' is not supported, use 'docker' or 'node12' instead.')

So the only way to get this working is to use the node:16 Docker container. Start-up of the action is not as fast as with Javascript actions but in my use case it doesn't matter. Runs of eslint-remote-tester-run-action are expected to take 5-6 hours anyways.

Once v8 is released as stable it might be worth to include short statement regarding Github Javascript Actions in release notes. I think there are couple of Github Actions created for linting projects on CI.

As there is nothing wrong with eslint@8 let's close this issue.
Thanks for all the help @mdjermanovic!

Triage automation moved this from Triaging to Complete Aug 29, 2021
@ljharb
Copy link
Sponsor Contributor

ljharb commented Aug 29, 2021

setup-node doesn’t have node > 12 yet, but https://github.com/ljharb/actions works fine :-p

@AriPerkkio
Copy link
Contributor Author

@ljharb by setup-node you mean actions/setup-node, right? It does support node >12.

With workflow

- uses: actions/setup-node@v2
  with:
    node-version: 14
- uses: AriPerkkio/eslint-remote-tester-run-action@test/eslint-v8

we end up in a situation where

The workflow is running node 14.17.5 but the action is running node 12.13.1.

The workflow runs npm install for installing eslint@8 but the action is the one running require('eslint') eventually.

The root cause is this line https://github.com/AriPerkkio/eslint-remote-tester-run-action/blob/a6174c3d08c4aa508075b310429321f623cc8fe2/action.yml#L31, where only allowed values are node12|docker. Replacing Github JavaScript action with Github Docker container action is the only possible solution here.

@ljharb
Copy link
Sponsor Contributor

ljharb commented Aug 30, 2021

Right, I'm saying that my action only has one version of node available for anything :-)

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Feb 26, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly repro:needed
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

4 participants