question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to add a resolver plugin to eslint or I will have to disable the import/no-unresolved rule? Here’s a plugin I use:

const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin')

module.exports = {
  resolve: {
    plugins: [
      new DirectoryNamedWebpackPlugin(true)
    ]
  }
}

Tried this but it didn’t work

//.eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      plugins: [new DirectoryNamedWebpackPlugin(true)]
    }
  }
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
egehandulgercommented, Apr 18, 2021

In https://github.com/benmosher/eslint-plugin-import#resolvers I can’t seem to find a way to use a plugin(perhaps I’m missing something)? I also can’t use eslint-import-resolver-webpack because of craco (I tried it without craco but it didn’t catch the plugin as well)

Anyone who comes here in the future. You certainly can use eslint-import-resolver-webpack. In the readme it mentions about this:

Will look for webpack.config.js as a sibling of the first ancestral package.json, or a config parameter may be provided with another filename/path either relative to the package.json, or a complete, absolute path.

Clearly, craco.config.js is not the same as webpack.config.js. To make both modules happy, create a webpack.config.js file as if there is no craco.

const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin')

module.exports = {
  resolve: {
    plugins: [new DirectoryNamedWebpackPlugin()],
  },
}

Then, require this file inside craco.config.js and use it where applicable/desired in accordance to craco format.

const webpackCustomConfig = require('./webpack.config')

module.exports = {
  webpack: {
    configure: (webpackConfig) => ({
      ...webpackConfig,
      resolve: {
        ...webpackConfig.resolve,
        plugins: [
          ...webpackCustomConfig.resolve.plugins,
          ...webpackConfig.resolve.plugins,
        ],
      },
    }),
  },
}

For eslint, you can configure webpack as documented in the readme:

settings: {
    'import/resolver': 'webpack',
  },
0reactions
shermendevcommented, Jan 26, 2020

A webpack plugin certainly can’t be dropped in to resolver settings;

I see, thank you for clarifying that out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolvers - webpack
These options allow users to change the resolving behavior through a variety of options including through resolve plugins . The resolver plugins, e.g. ......
Read more >
Resolver - Parcel
Resolver plugins are responsible for turning a dependency specifier into a full file path that will be processed by transformers. Resolvers run in...
Read more >
webpack-theme-resolver-plugin - npm
This is a Resolver-Plugin for webpack. It enables resolving files by looking up multiple directories in a chain with an fallback package. This ......
Read more >
Toolchain Resolver Plugins - Gradle User Manual
This page explains how to author a toolchain resolver plugin. For details on how toolchain auto-provisioning interacts with these plugins, see Toolchains.
Read more >
SLS Resolver Plugins - hub.source - idem Documentation
Idem SLS resolvers are very easy to write and can often work in just a few lines of code. They are implemented in...
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