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

Failed to load plugin in monorepo #1871

Open
dev-justtrade opened this issue Jul 28, 2022 · 5 comments
Open

Failed to load plugin in monorepo #1871

dev-justtrade opened this issue Jul 28, 2022 · 5 comments
Labels
meta Issues related to the plugin itself

Comments

@dev-justtrade
Copy link

ESLint with plugin unicorn brakes in a NX monorepo when having packages on a deeper folder level.

It works fine in packages like /libs/first-level (path @nx-monorepo/first-level) but throws this error when used in packages like /libs/first-level/second-level (path @nx-monorepo/first-level/second-level):

Error: Failed to load plugin 'unicorn' declared in '.eslintrc.json » ../../../.eslintrc.json': Invalid name: "@nx-monorepo/first-level/second-level"

Error: Failed to load plugin 'unicorn' declared in '.eslintrc.json » ../../../.eslintrc.json': Invalid name: "@nx-monorepo/first-level/second-level"
    at ensureValidName (/home/xxx/nx-monorepo/node_modules/normalize-package-data/lib/fixer.js:336:15)
    at Object.fixNameField (/home/xxx/nx-monorepo/node_modules/normalize-package-data/lib/fixer.js:215:5)
    at /home/xxx/nx-monorepo/node_modules/normalize-package-data/lib/normalize.js:32:38
    at Array.forEach (<anonymous>)
    at normalize (/home/xxx/nx-monorepo/node_modules/normalize-package-data/lib/normalize.js:31:15)
    at module.exports.sync (/home/xxx/nx-monorepo/node_modules/read-pkg/index.js:37:36)
    at module.exports.sync (/home/xxx/nx-monorepo/node_modules/read-pkg-up/index.js:27:24)
    at Object.<anonymous> (/home/xxx/nx-monorepo/node_modules/eslint-plugin-unicorn/rules/expiring-todo-comments.js:50:33)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

I seems to be related to the expiring-todo-comments rule.

@schmkr
Copy link
Contributor

schmkr commented Oct 20, 2022

Also experiencing this issue, in an NX monorepo.

Would it be an idea, to add a configuration option for the location of the package.json to use? Similar to how import/no-extraneous-dependencies does this?

@schmkr
Copy link
Contributor

schmkr commented Oct 20, 2022

@dev-justtrade Do you also get this error only in an editor (WebStorm) and not when running nx lint?

@fregante
Copy link
Collaborator

fregante commented Nov 10, 2022

Is this issue specific to unicorn? I don’t think a plugin can decide where eslint can find it.

This is likely a user issue. Ask for info in NX's forums

@schmkr
Copy link
Contributor

schmkr commented Dec 12, 2022

@fregante the issue is specific to a dependency unicorn uses, because the name property automatically generated by Nx are considered invalid according to the normalize-package-data package (which is a transitive dependency of this project). Those package.json files are only meant for internal use, they are not plubished to an NPM registry, but consumed as a locally built package and the package names correspond to their mapping in Typescript. Something Nx refers to as "buildable libraries".

The issue happens in the rules/expiring-todo-comments.js as a result of this block:

const packageResult = readPkgUp.sync();
const hasPackage = Boolean(packageResult);
const packageJson = hasPackage ? packageResult.packageJson : {};

Changing that first line to const packageResult = readPkgUp.sync({ normalize: false }); will skip validation of the package.json data and the error disappears. Reading up on what the normalization all validates and comparing that with what data is consumed (only the list of dependencies and devDependencies), to me this seems like the normalization is not really needed.

Would you agree?

@schmkr
Copy link
Contributor

schmkr commented Dec 22, 2022

FYI I have created a PR (#2020) with the above suggested change.

schmkr added a commit to schmkr/eslint-plugin-unicorn that referenced this issue Dec 22, 2022
@fregante fregante added the meta Issues related to the plugin itself label Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Issues related to the plugin itself
Projects
None yet
Development

No branches or pull requests

3 participants