Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating with Vite + React + TS #160

Closed
LunaWanderer1 opened this issue May 5, 2023 · 4 comments
Closed

Integrating with Vite + React + TS #160

LunaWanderer1 opened this issue May 5, 2023 · 4 comments

Comments

@LunaWanderer1
Copy link

I followed the steps outlined here https://design-system.alpha.canada.ca/en/installation/

I'm having an issue integrating this library with Vite + React + TS.

I tried importing via:

import { GcdsHeader } from '@cdssnc/gcds-components-react/';

but only this seems to import it:

import { GcdsHeader } from '@cdssnc/gcds-components-react/dist';

Once that error clears up I end up with additional errors:
image

Feel free to take a look at the reproduction of the error here:

https://stackblitz.com/edit/vitejs-vite-k6yxw2?file=src/App.tsx

This other github issue may also be some help:
vitejs/vite#12434

@LunaWanderer1
Copy link
Author

LunaWanderer1 commented May 5, 2023

Hi,

I have managed to get it to work with the following steps:

  1. Add the following to vite.config.ts
optimizeDeps: {
	exclude: ['@cdssnc/gcds-components-react'],
},
  1. Change import to the following:
import { GcdsHeader } from '@cdssnc/gcds-components-react/dist';

  1. Removing this line from the code:

I'm fine with adding Step 1 and Step 2, it's seems to be a common issue in the Vite community but the third step may require a change to this component library.

Thanks,

Eli

@LunaWanderer1
Copy link
Author

After realizing those files are generated by Stencil, I looked more into it and the following works in the vite.config.ts.

optimizeDeps: {
	exclude: ['@cdssnc/gcds-components-react'],
	include: ['react-dom'],
},

Seems to resolve any issues, may want to add a note in the React installation section to help others!

@ethanWallace
Copy link
Collaborator

Thanks @eliyammine for the updates!

With our latest update(v0.10.2) to the component packages, we have hopefully solved the issue you were having in step 2. You should now be able to import the components with import { GcdsHeader } from '@cdssnc/gcds-components-react now.

For the third step I am glad you found a solution to the issue since as you mentioned that file is generated by stencil so modifying it is not really an option. With that said, I am still going to look into the issue a little more to see if there is anything on our end that can be done so you don't need to do the additional step with react-dom on installation.

@LunaWanderer1
Copy link
Author

Thank you! That did indeed fix it.

For the third step, I did find some cases of needing to include react-dom but not as common as the exclude statement. Seems to just be an issue with Vite(Rollup or esbuild) so may not be worth your time to look into it much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants