primereact icon indicating copy to clipboard operation
primereact copied to clipboard

PrimeReact components not showing in import suggestions

Open bn-piar opened this issue 2 years ago • 18 comments

Describe the bug

In VSCode primereact components are not in the list of available imports image

Reproducer

https://codesandbox.io/s/interesting-christian-t61g1y?file=/src/index.js

PrimeReact version

9.2.3

React version

18.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

chrome

Steps to reproduce the behavior

  1. bootstrap a project (cra, nextjs, redwoodjs)
  2. install primereact dependencies
  3. in a component add a primereact component
<Button />
  1. call actions menu (ctrl+space or ctrl+.)
  2. find there no Button import suggestion

Expected behavior

primereact components appear in suggestions

bn-piar avatar Apr 18 '23 06:04 bn-piar

I get this issue too in VSCode once in a while. Sometimes its working other times it is not and I have not quite figured out why?

melloware avatar Apr 18 '23 13:04 melloware

I think it has to do with the IDE's compiler. Sometimes it can't find PrimeReact or any library even though it is installed. Test;

https://user-images.githubusercontent.com/11868120/233268633-c255569b-4875-402a-afe7-1d7b48308552.mov

mertsincan avatar Apr 20 '23 05:04 mertsincan

@mertsincan hey. I'm having the same issue. No other library have their imports missing from import suggestion list. It only occurs with primereact components =( It's not dependent on the IDE. The same behavior repeats in Codesandbox, VSCode and Code-OSS. What you show in your "test" video is not import suggestions but component props. Delete Button import and try again

bnn1 avatar Apr 22 '23 03:04 bnn1

Agreed @mertsincan its on the initial Typing of <Button> it does not suggest the PrimeReact import.

melloware avatar Apr 22 '23 11:04 melloware

I found this fixes import suggestions: Add index.ts file to the root primereact folder, export * from all components

// primereact/index.ts
export * from './button'
// ... rest exports

bn-piar avatar Apr 24 '23 03:04 bn-piar

@bn-piar I had this in 8.6.0 see: https://github.com/primefaces/primereact/issues/3288

But it was reverted in 8.7.1 because it was causing too many issues with people not understanding the difference in importing with Tree Shaking: https://github.com/primefaces/primereact/issues/3513

melloware avatar Apr 24 '23 11:04 melloware

lack of auto import is a significant drawback because it forces me to manually import components, which can be time-consuming.

bnn1 avatar Apr 24 '23 17:04 bnn1

Totally agree I am just saying the global index.d.ts was removed because right now each component is individual for tree shaking purposes so the final bundle of JS only includes the actual components you use. I would love to solve this so a global index.d.ts can also be provided but doesn't cause issues.

melloware avatar Apr 24 '23 17:04 melloware

@bn-piar do you want to submit a PR to review?

melloware avatar Apr 24 '23 19:04 melloware

I believe only major changes would fix the issue. Like rewriting the whole library in typescript. Or separating modules that require 3rd party packages from the core package. Or both.

bnn1 avatar Apr 26 '23 04:04 bnn1

@bnn1 I created a simple VS Code extension for code suggestions and quick fixes. can be used as a temporary solution https://marketplace.visualstudio.com/items?itemName=kl-nevermore.primereact-import-helper

kl-nevermore avatar Dec 29 '23 08:12 kl-nevermore

@kl-nevermore this is nice how are you auto-generating this plugin? Is your project on GitHub?

melloware avatar Dec 29 '23 12:12 melloware

It works for me without extension

bnn1 avatar Dec 29 '23 16:12 bnn1

@bnn1 i thought you reported above it was not working for you?

melloware avatar Dec 29 '23 16:12 melloware

@melloware it is working now

bnn1 avatar Jan 01 '24 10:01 bnn1

@bnn1 did you do anything to make it work? I'm facing the same issue.

N1rm4l avatar Jan 05 '24 13:01 N1rm4l

@melloware @N1rm4l I've tested it a few months back, it was working. Just tested it again and it's not working anymore ¯\(ツ)

also, this problem doesn't exist in Webstorm (autoimports are working in webstorm)

bnn1 avatar Jan 05 '24 14:01 bnn1

I created a simple VS Code extension for code suggestions and quick fixes. can be used as a temporary solution https://marketplace.visualstudio.com/items?itemName=kl-nevermore.primereact-import-helper

I released 0.1.0 a few days ago to fix known bugs can try it

kl-nevermore avatar Jan 05 '24 14:01 kl-nevermore