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.

[Bug]: @carbon/react/icons module does not provide IDE import auto-complete

See original GitHub issue

Package

@carbon/react

Browser

No response

Package version

1.1.0

React version

not specific to a version of react

Description

When importing icons via the @carbon/react/icons re-export, no auto-completions are provided in VS Code:

image

versus @carbon/icons-react which looks like:

image

It doesn’t look like the IDE auto-completion is smart enough to follow the combination of Object.keys and Object.defineProperty to provide the exhaustive list of icons that are available at runtime/build time.

image

Though I’m not sure exactly how to accomplish it, it seems like a more direct re-export of the icons from the required module would be what is needed to get past this.

There’s also an info message that pops up in vscode for this import which is not present on the icons-react version:

image

versus icons-react which has a full-blown d.ts file to which it links that provides type info:

image

CodeSandbox example

n/a

Steps to reproduce

  1. Install @carbon/react into a React project
  2. Open a component file in an IDE like VS Code
  3. Attempt to import an icon from @carbon/react/icons
  4. Observe that the auto-complete list does not show any of the available icons

Code of Conduct

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:23 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
jdharvey-ibmcommented, Aug 5, 2022

@metonym unfortunately for my use case I don’t believe that would help. The issue I have when working with the icons through the @carbon/react export is that the index.js file at @carbon/react/icons/index.js does not appear to be defined in a way in which VS Code can compute the available imports for the icons package. Something about the cjs syntax in it and the use of defineProperty isn’t properly recognized. index.esm.js works fine though since the only contents of that file are export * from '@carbon/icons-react';

1reaction
jdharvey-ibmcommented, Aug 5, 2022

Confirmed that when I import via @carbon/react/icons/index.esm, I get the right set of imports available, which is awesome.

The main thing still outstanding for this issue is that I don’t get the auto-complete from the standard @carbon/react/icons import; I have to use the more-specific index.esm one. Not a huge deal, but wanted to note it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autocomplete Bug - Import path is missing .js file extension ...
This is not a bug. This is intended default behavior that predates ESM and it's requirement to have .js in imports.
Read more >
Auto complete does not always add the import statement
It does that with built in modules, installed modules and local modules. Note that when it refuses to import a given symbol with...
Read more >
How to get PyCharm IDE to do code completion for pygame's ...
Here is how you can fix this issue specifically for pygame: Go to your pygame folder and open __init__.py in a text editor;...
Read more >
Autocomplete not working for specific targets - Arduino IDE 2.0
Hello, Over the course of me using Arduino IDE I noticed the autocomplete (or as it is called in the settings "Editor Quick...
Read more >
Intellisense not picking up Module imports.
If you are able to provide more information, you can request the issue being ... Error (active) E3275 could not find module file...
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