Fork me on GitHub
#reagent
<
2017-10-31
>
p-himik10:10:21

Could someone please shed some light on how to use :npm-deps with Reagent 0.8 with packages that require React? If I don't add react, react-dom and create-react-class to :npm-deps, the build process fails with Error: Can't resolve 'react' in '%project_dir%/node_modules/react-measure/lib'. Apparently, I need to explicitly add React to :npm-deps? If I add all those, the build process goes just fine, but then I see Uncaught ReferenceError: process is not defined in the browser's console. According to https://github.com/reagent-project/reagent/blob/master/docs/0.8-upgrade.md I can use :shim-process (apparently was renamed to :process-shim) option to tackle that. But adding :process-shim true does nothing in my case.

p-himik10:10:00

Huh, but after all messages, if I test for process.env in the browser's conole - it's there. Maybe it's the matter of dependency order of some sort?

p-himik10:10:11

Yeah, env.js appears waaay below in the network requests log. Hmm...

juhoteperi12:10:59

Might be easier to just install deps with npm install (and save to package.json) than to use :npm-deps

juhoteperi12:10:28

Node 8 / npm 5 had some strange issues with npm install removing all packages except those in install command, but maybe they were solved already

juhoteperi12:10:29

Not sure about process.env, works for me with React at least, and I think React uses it

juhoteperi12:10:36

Fixed the option name in upgrade guide

p-himik12:10:19

@juhoteperi I asked in the #clojurescript channel - apparently preloads (including the one that's supposed to introduce process.env) are loaded only after all dependencies have been loaded. React does use process.env, and during loading as well. How exactly do you load React?

juhoteperi12:10:15

"Normally", try Reagent by starting figwheel from test-environments/browser-node-react-16, that should use process shim

juhoteperi12:10:03

hmmh, starting figwheel for that env requires some lein profile

juhoteperi12:10:37

Ah no, process-shim is enabled in the default build

p-himik12:10:05

Interesting - in the generated cljs_deps.js the entry goog.addDependency("../process/env.js", ['process.env'], ['cljs.core']); does go right after cljs.core, just as the documentation on CLJS compiler states. But for my code that's not the case. I'll keep digging.

p-himik12:10:58

I think the issue is that process.env is added as the last preload. Hence, if any previous preload has any dependencies (like my preload that calls re-frisk.core/enable-re-frisk!), they will be included before process.env.

juhoteperi13:10:20

That sounds plausible, you can workaround this for now by enabing re-frisk from app code instead of preload