xojs/xo

Named export 'Legacy' not found when running in CI with 0.46+

Primajin opened this issue · 5 comments

Hey there I am facing an issue with running xo in CI. Since the upgrade from 0.45 to 0.46+ it always fails with the error:

file:///home/runner/work/eyesbound/eyesbound/node_modules/xo/lib/options-manager.js:17
import {Legacy} from '@eslint/eslintrc';
        ^^^^^^
SyntaxError: Named export 'Legacy' not found. The requested module '@eslint/eslintrc' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@eslint/eslintrc';
const {Legacy} = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Node.js v17.0.1
Error: Process completed with exit code 1.

I tried running it in Node 16/17 // npm 7/8 but both failed.
Weirdly it works fine locally - just not in github CI.
https://github.com/Primajin/eyesbound/runs/4059394186

Even in the one from the github bot: Primajin/eyesbound#83

Any idea?

Ahh it was

npm install --legacy-peer-deps

that fixed it! 🎉

https://github.com/Primajin/eyesbound/runs/4059433195?check_suite_focus=true#step:4:1

The reason why it worked locally is that I have set that as default to use legacy peer deps 🤦🏻‍♂️

I had the same issue. So I started using npm ci --legacy-peer-deps based on the previous comment. I trying to upgrade to XO 0.47.0.

Though now it fails during runtime:

Error: Failed to load plugin 'unicorn' declared in 'BaseConfig » /home/runner/work/robot-api/robot-api/node_modules/xo/config/plugins.cjs': Cannot find module 'eslint/package.json'
Require stack:
- /home/runner/work/robot-api/robot-api/node_modules/eslint-plugin-unicorn/rules/utils/get-builtin-rule.js
- /home/runner/work/robot-api/robot-api/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js
- /home/runner/work/robot-api/robot-api/node_modules/eslint-plugin-unicorn/rules/utils/rule.js
- /home/runner/work/robot-api/robot-api/node_modules/eslint-plugin-unicorn/index.js
- /home/runner/work/robot-api/robot-api/node_modules/xo/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
Referenced from: /home/runner/work/robot-api/robot-api/node_modules/xo/config/plugins.cjs
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at getBuiltinRule (/home/runner/work/robot-api/robot-api/node_modules/eslint-plugin-unicorn/rules/utils/get-builtin-rule.js:5:24)
    at Object.<anonymous> (/home/runner/work/robot-api/robot-api/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js:7:18)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:[32](https://github.com/tue-robotics/robot-api/runs/5096740979?check_suite_focus=true#step:6:32))
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

I am running it with the following config:

  "xo": {
    "parser": "babel-eslint",
    "space": true,
    "parserOptions": {
      "ecmaVersion": 2021
    },
    "envs": [
      "mocha"
    ],
    "ignores": [
      "dist/**",
      "lib/graveyard/*"
    ],
    "rules": {
      "capitalized-comments": "off",
      "no-unused-expressions": [
        2,
        {
          "allowShortCircuit": true
        }
      ],
      "new-cap": [
        "error",
        {
          "capIsNewExceptions": [
            "ActionClient",
            "Service",
            "Topic"
          ]
        }
      ]
    },
    "overrides": [
      {
        "files": "test/*.js",
        "rules": {
          "import/extensions": "off"
        }
      }
    ]
  }

Ok, be replacing babel-eslint to @babel/eslint-parser the problem was solved. Also no -legacy-peer-deps is needed.

Yes I can confirm legacy deps is not needed any more. I guess with that option you would need to add unicorn explicitly as peer dependency which new npm now gets automagically