Eslint error: 'dependency' should be listed in the project's dependencies

See original GitHub issue

Background

When I generate a new roc project I see that eslint picks up a lot of errors similar to the one below:

screen shot 2017-05-15 at 11 04 10

My understanding of this problem is that this is a result of roc’s design choices: roc takes over the responsibility of handling such dependencies for me: my project no longer depends on react, it depends on roc and roc depends on react.

However, since eslint is a stage of my CI process, I cannot have any eslint errors in my code.

Questions

  1. How would you recommend solving this?
  2. Is adding the roc dependencies as peerDependencies in my project a good solution?
  3. Can this be done automatically by roc so I don’t have to do it manually each time?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
dlmrcommented, May 15, 2017

To support this in an optimal way we need to do as what @fix-fix suggests, creating a eslint-import-resolver-roc and probably a eslint-config-roc as well. I have thought about doing this myself but never gotten around to it and if someone is up for it I think it would be a great addition to the ecosystem and something I think we could host under this organization.

To manage this currently I often just either set this rule to a warning or turn it off completely.

With that said, I could not stop myself from giving this some more thought and I now have something you can test in your project @wadim.

Note that this is an experiment and should be optimized further in the future if it works.

.eslintrc

Example that uses eslint-config-airbnb

{
  "extends": [
    "eslint-config-airbnb",
    "./eslint-config-roc.js"
  ]
}

eslint-config-roc.js

const path = require('path');

// Registers the runtime to be able to read the Roc Context
require('roc/runtime/register');

const context = require('roc/lib/context/helpers/manageContext').getContext();
const coreModules = Object.keys(context.dependencies.exports);

module.exports = {
  settings: {
    'import/resolver': path.resolve('./eslint-import-resolver-roc'),
    // Uses core-modules here to make eslint-plugin-import not complain about dependencies
    // missing from package.json - the only way to manage this today
    'import/core-modules': coreModules
  }
};

eslint-import-resolver-roc.js

const path = require('path');
const resolver = require('roc').getResolveRequest('eslint-plugin-import');

const resolve = require('resolve');

module.exports.interfaceVersion = 2;

module.exports.resolve = function eslintImportResolver(source, file) {
  const context = path.dirname(path.resolve(file));

  if (resolve.isCore(source)) {
    return { found: true, path: null };
  }

  try {
    return {
      found: true,
      path: resolve.sync(resolver(source, context), { basedir: context })
    };
  } catch (err) {
    /* ignore this error and try again instead with fallback enabled */
  }

  try {
    return {
      found: true,
      path: resolve.sync(resolver(source, context, true), { basedir: context })
    };
  } catch (err) {
    return { found: false };
  }
};
1reaction
fix-fixcommented, May 15, 2017

It should be solved by writing custom resolver for eslint-plugin-import (or maybe just using eslint-import-resolver-webpack, if it’s possible to provide webpack config at runtime), see docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint should be listed in the project's dependencies, not ...
I give the specifics in this post: ESLint error: '@storybook/react' should be listed in the project's dependencies, not devDependencies.
Read more >
import/no-extraneous-dependencies: Complains about node ...
It throws an error which says 'path' should be listed in the project's dependencies. Run 'npm i -S path' to add it.
Read more >
ESLint - npm
Make sure your plugins (and ESLint) are both in your project's package.json as devDependencies (or dependencies, if your project uses ESLint at runtime)....
Read more >
Vite and @vitejs/plugin-vue as devDependencies - Reddit
I got these ESlint errors in vite.config.js file: '@vitejs/plugin-vue' should be listed in the project's dependencies, not devDependencies.
Read more >
A Guide to ESLint | Laurie on Tech
The above code will only show a linting error when core dependencies are imported but not included. Any other dependency type can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found