Fork me on GitHub
#shadow-cljs
<
2024-01-01
>
Pranav Ram13:01:34

I'm unable to import a local js file: HierarchyForm.js

import React from 'react'
import validator from '@rjsf/validator-ajv8';
import Form from "@rjsf/mui"
export default HierarchyForm = () => {
    return (
        
); };
But if I replace the Form with a plain div, it's importing fine. Are additional dependencies apart from React an issue here? I tried the same with MUI too

thheller13:01:15

I assume you mean import this file from CLJS?

thheller13:01:05

otherwise I'm unsure what you are asking, this is not the right channel to ask JS questions 😛

Pranav Ram13:01:48

Yes! Sorry! Importing it into a uix2 project using shadow-cljs

Pranav Ram13:01:24

I've setup the gen path like the document suggests and using (require '["/js/test/HierarchyForm" :default HierarchyForm]) to import it

thheller13:01:58

ok, this is a JSX file, so directly importing it is not supported

thheller13:01:08

do you convert it to actual JS first?

thheller13:01:32

whats the point of making this is a JS file? why not write it in CLJS?

Pranav Ram13:01:03

Oh I have used babel:

import React from 'react';
import validator from '@rjsf/validator-ajv8';
import Form from "@rjsf/mui";
export default HierarchyForm = () => {
  return /*#__PURE__*/React.createElement(Form, {
    schema: {
      type: 'string'
    },
    validator: validator
  });
};

Pranav Ram13:01:33

Rational is that other teams can also use the plain JS files directly

Pranav Ram13:01:54

currently multiple Typescript projects underway with this being the only CLJS project

thheller13:01:16

if you are going to have a lot of JS I do not recommend including it this way. the direct JS import will get you in trouble, or rather that it is getting processed via the closure compiler

thheller13:01:27

you probably either want :target :npm-module or :esm and let JS tools process the leftover JS

Pranav Ram13:01:08

Oh so you're suggesting changing the shadow-cljs config to import this as is and then process via another tool? Curious how the React import gets by this problem

thheller13:01:03

I don't know what the problem is, you can debug it. you didn't say what the error is so I have nothing to go by

thheller13:01:45

the closure compiler is quite strict in how it handles import, so there might be differences to how other JS tools do it

thheller13:01:05

but if you have lots of JS code you are better off using :npm-module and letting something like webpack process the JS

thheller13:01:14

and put your JS files into some "package" so you import them via (:require ["your-package/HierachyForm" :as x]) or whatever

thheller13:01:26

and then have webpack map your-package to your actual sources

Pranav Ram15:01:45

I see, let me try that. Btw here is the error in the console. Probably have something to do with the way the compiler is resolving the other dependencies? If I can share anything more detailed with you please let me know interim.