Fork me on GitHub

So, I haven’t been able to figure out how to get this to work still. I tried adding :target :bundle to my build.edn , but that didn’t seem to have an effect. I think part of the issue is that I’m not trying to import something from node_modules. I’m trying to import a JavaScript file from within my project. Relative to my core.cljs file, it’s located at ../../storybook/index.js. In JavaScript, I would import by doing something like import StorybookUIRoot from '../../storybook'. In Clojurescript, I’m not sure how to do that - I’ve tried lots of incantations and none of them worked (most of them I didn’t expect to work):

:require [storybook]
:require [../../storybook :as storybook]
:require [(symbol ../../storybook :as storybook]
(js/require "../../storybook")
Since I haven’t been able to find any documentation about how to require JavaScript that is within my project (and not in node_modules), I’m not sure where the problem lies. I’ll try to narrow it down through experimentation and maybe reading some code to understand how the different pieces are supposed to work.


I’ve managed to require my own JavaScript by a creating a local npm module:

👍 2

After that, you can require it like any other JS library via package.json

"mylocalmodule": "./npm-local/mylocalmodule",


yarn install (that’s required, I think)


./npm-local/mylocalmodule is located in the top-level React Native directory of your project


npm-local is not a required name, that’s just how I named it


After that, from CLJS you should be able to:

(:require [mylocalmodule :as xyz])


Great idea! I thought of doing something like that with npm link or something but I think I like your idea even better, since it gives me more flexibility where I put my code. I’ll give that a try!

👍 2

the storybook npm library is the standalone CLI command you are supposed to use for storybook?


why are you trying to include it in a CLJS build? its not meant to be used as a library


(unless that has changed since I last looked)


oh nevermind. its your file not something from storybook

👍 2

Yes, more specifically it’s the file created by the storybook command:

npx -p @storybook/cli sb init --type react_native


@soxley right, you cannot put paths in the ns form in ClojureScript - we could probably support some very restricted pattern - like foo/index.js for local node_module resolution?


though ... probably least problematic thing to do and the most minimal change, is just to allow additional paths for node_modules indexing - seems like that would cover this problem

👍 2

I’m trying to split my shadow-cljs + expo project into different namespaces for difference platforms, but coming up show on examples/documentation. Curious if and how this can be done?


whats the problem? you create the ns and then a second build config using that ns?


So instead of :react-native as the :target, use :android, :ios, or :web?


ah you just mean expo target? I thought you meant actually switching the code that gets compiled, not what expo makes out of that


can't comment on the expo part. shadow-cljs stays with :target :react-native, you just start the expo thing differently I guess


Hm, maybe I need a dynamic require? The platform comes from the OS function on react-native/Platform


I need to require based on platform


no, flip it. you build based on the target platform. and whatever you build directly requires that it needs


so you create a and/or namespace for each


and require whatever you need from there? each with its own build


at least thats the theory. dunno how all that works combined with expo


ok thanks! I'll give that a try