import-js / import-js/eslint-plugin-import

Error when importing images using aliases

Open
#2,230 34 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Hello all,

Recently I have updated my project and my eslint has started complaining when I import an image using an alias (extraneous dependency error). In order to get rid of this error I added:
"import/ignore": ["/*.png/", "/*.jpg/"]

Which made my webpack build is ok as expected. However, VSCode highlights my "import myimage from @Images/my_image.png" as red due to "import/no-extraneous-dependencies".

On the other hand if I have:
"import/ignore":["*.png", "*.jpg"]

Then the highlight red error from VSCode goes away but my webpack build throws:

ERROR in Invalid regular expression: *.png: Nothing to repeat
Occurred while linting blabla\index.js:2

It looks like VSCode ESLint plugin and webpack eslint stuff do not use the same patterns for import/ignore.

I have created the following repo where I get the same result:
https://github.com/javierguzman/eslint-error

You may need to do npm install --force for the node_modules.

In order to reproduce the error:

  1. Open Header.tsx and you will see no error highlights
  2. Run "npm run build:production"
  3. You get the invalid regular expression
  4. Change the expression of import/ignore
  5. Run "npm run build:production" and it is ok
  6. However if you go to Header.tsx you will see the import marked as red due to extraneous dependencies

I hope my configuration is not that bad 😄 I have two eslint configuration, one for development and one for production. build:production as well as vscode uses the production es lint configuration. This can be seen in the vscode configuration folder under the repository I have created.

Please, let me know if you need something else from me.

Thank you in advance for the help and regards

p.s. the lint configuration to be looked at is .eslintrc.json, ignore the development one

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Clone the linked reproduction repository, inspect the production .eslintrc.json and the VSCode configuration, then run npm install --force and npm run build:production. Compare how the two environments interpret the import/ignore patterns in Header.tsx. Done means the image alias is handled consistently without an invalid regular expression or an extraneous-dependency highlight.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, webpack
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.