figwheel-main

2022-06-24T16:48:04.481149Z

Hi, trying to use https://github.com/Hacker0x01/react-datepicker in a figwheel-main project. Have added to project with yarn add react-datepicker (can see it in the package.json and in node_modules ) I'm importing it with ["react-datepicker" :refer [DatePicker]] . If I log out DatePicker it is undefined. If I try to construct one (eg: [:> DatePicker {:selected (js/Date.)}] ) then I get `Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.` Other third party react components are in the project and working fine. Can someone nudge me in the right direction?

dominicm 2022-06-24T17:03:40.654319Z

Has webpack been rerun since you added it?

dominicm 2022-06-24T17:04:04.375129Z

There's an :auto-bundle option you can enable iirc

dominicm 2022-06-24T17:04:29.978839Z

Also, hi 👋

2022-06-24T17:13:27.318349Z

Hey Dominic 👋. I already have :auto-bundle :webpack in the metadata in web.cljs.edn

dominicm 2022-06-24T17:14:29.587619Z

I mentioned the wrong option... I meant smart-bundle or bundle-freq I believe.

dominicm 2022-06-24T17:14:53.180389Z

:bundle-freq :smart

dominicm 2022-06-24T17:15:11.101719Z

By default, figwheel only runs the bundle command once.

dominicm 2022-06-24T17:16:10.897009Z

The easiest way to test this theory is to just restart figwheel I think. It will bundle on startup and tada.

2022-06-24T17:17:24.402019Z

It is unaffected by restarting figwheel

dominicm 2022-06-24T17:18:45.577259Z

Huh, that is odd. Okay, if you look into your cljs output folder you should find an npm_deps.js file. Is your require in there?

2022-06-24T17:20:55.966689Z

the require is there

2022-06-24T17:21:32.576799Z

The linter complains "no declaration file for module" though

dominicm 2022-06-24T17:21:57.753529Z

Cool. Good. I suspect then that the webpack command is failing for some reason. I can't remember how figwheel runs the command and what it does with the output.

dominicm 2022-06-24T17:22:06.981659Z

You can try running it manually to see.

dominicm 2022-06-24T17:32:39.812599Z

https://github.com/bhauman/figwheel-main/blob/master/src/figwheel/main.cljc#L127 the command is logged, but the output isn't.

dominicm 2022-06-24T17:32:59.302619Z

Check your logs for the command, and run manually. That should give you what you need 😃

2022-06-24T17:45:50.570259Z

webpack runs happily

dominicm 2022-06-24T17:46:30.522439Z

Any chance you have a cached js file?

2022-06-24T17:56:48.844419Z

ran yarn cache clean

2022-06-24T18:17:26.422289Z

I'll bang my head against this again on Monday I think 😵 thanks for the help so far Dominic, have a good weekend

dominicm 2022-06-24T18:18:15.117939Z

I'd start poking at the bundle output to see if your npm dependency is in there

athomasoriginal 2022-06-24T19:27:21.566669Z

do you see react-datepicker in target/public/cljs-out/build-name/npm_deps.js ?

2022-06-24T19:31:43.838039Z

Yeah it's required there

athomasoriginal 2022-06-24T19:33:32.967739Z

sweet. if you just require it as (require ["react-datepicker" :as datepicker) and console log datepicker what do you see?

dominicm 2022-06-24T19:34:25.954859Z

Haha, right. Obvious question I didn't ask: how are you using the required date picker 🤦

dominicm 2022-06-24T19:34:36.386579Z

I should write a debugging flowchart for this

👍 1
2022-06-24T19:34:39.017129Z

it's undefined if I log it out

athomasoriginal 2022-06-24T19:35:12.679469Z

does the require name match the name is npm_deps.js ?

dominicm 2022-06-24T19:36:17.262669Z

import DatePicker from "react-datepicker";

dominicm 2022-06-24T19:37:55.852309Z

https://clojurescript.org/news/2021-04-06-release is this the form that will end up needing $default in there?

athomasoriginal 2022-06-24T19:38:49.850139Z

well, it depends. First step is to get something other than undefined and then we can try $default which is more of a convenience than a must have 🙂

2022-06-24T19:39:00.872239Z

> sweet. if you just require it as (require ["react-datepicker" :as datepicker) and console log datepicker what do you see? Sorry, misread this - will try :as rather than just :refer ing DatePicker in a mo (AFK)

👍 1
dominicm 2022-06-24T19:39:13.299959Z

Ah, yes. That's definitely it then

athomasoriginal 2022-06-24T19:39:18.303599Z

hah nice

dominicm 2022-06-24T19:39:57.045299Z

@tkjone do you know if anyone has written a conversion guide for es6 to cljs requires yet? Like the shadow one.

athomasoriginal 2022-06-24T19:40:46.021319Z

How do you mean conversion guide? Like, if the JS lib uses ES6 module how do we translate those into CLJS?

dominicm 2022-06-24T19:42:07.998279Z

https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages like this, yep

athomasoriginal 2022-06-24T19:46:09.305899Z

If there is, I have yet to find it. There is the official CLJS docs which I believe are still accurate though.

dominicm 2022-06-24T19:46:40.837999Z

I don't think they cover it in this way though. It would be a useful resource 🙂

👍 1
athomasoriginal 2022-06-24T19:47:21.439179Z

100% agree. I've yet to sit down and really understand the requires, otherwise I would 100% contribute to the CLJS docs because as you noted, it would be useful

2022-06-24T20:33:21.477319Z

okay ["react-datepicker$default" :as DatePicker] does the job! Thanks for the help guys 🙏

1
🎉 1