Fork me on GitHub
#shadow-cljs
<
2018-08-04
>
steveb8n03:08:42

I’m using the “promesa” lib on node.js (in an AWS lambda) and seeing an error that suggests that the release compile is obfuscating a promesa fn when it shouldn’t. Anyone seen this before or have an example of promesa being advanced compiled with shadow?

2018-08-04T02:57:14.739Z	15b1728f-9792-11e8-bf66-b982ac270145	TypeError: this.Rd is not a function
at Promise.f.promesa$protocols$IPromise$_catch$arity$2 (/var/task/handlers.js:680:71)
at zz (/var/task/handlers.js:676:641)
at Kz (/var/task/handlers.js:682:442)
at Fo (/var/task/handlers.js:778:164)
I am using deps.edn for classpath/deps. I wonder if that’s causing the problem?

steveb8n03:08:14

I just read the docs on https://shadow-cljs.github.io/docs/UsersGuide.html#_simplified_externs. I’ll see if that can fix the problem

thheller07:08:47

@steveb8n turn on :compiler-options {:infer-externs :auto} if you haven't. run shadow-cljs release your-build --pseudo-names to figure out what .Rd is.

pez07:08:48

@thheller: thanks! Glad to hear there is hope! 😃 Tried it now, using import * as shadowBrowser from '../lib/shadow.cljs.devtools.client.browser', as the first clsj import being done, but it doesn’t fix the problem. Worse, it makes the release build fail. What am I not understanding correctly?

thheller07:08:39

well yeah thats the problem. the file only exists in dev builds and you must conditionally require it

thheller07:08:49

but you can't do conditional requires with import

thheller07:08:19

typically you would if (process.env.NODE_ENV == "development") { require("../lib/shadow.cljs.devtools.client.browser"); }

thheller07:08:39

you can maybe do this after all the imports though

thheller07:08:54

don't know how other tools deal with import and require in the same file

thheller07:08:07

are you actually running in the browser though? not exactly sure how vscode works internally. maybe its a node environment?

pez08:08:48

I think it is a node environment. 😀

thheller08:08:13

which error do you get though?

thheller08:08:23

it should at least print something in the console?

pez08:08:13

The error message when the release build fails?

thheller08:08:02

no dev stuff

thheller08:08:12

you should get some kind of message when the devtools either fail to load or connect

pez08:08:57

Ok, not at the computer right now, but will check ASAP. Should I be using the browser client, even though it is a node environment?

thheller08:08:49

probably no but isn't it based on electron? which is this weird hybrid

pez09:08:41

Yes, Electron.

pez10:08:29

No, I can’t find any output from the devtools anywhere.

thheller10:08:48

check the generated lib/cljs_env.js file please

thheller10:08:59

the CLOSURE_DEFINES in particular?

thheller10:08:22

is the code available somewhere? I can take a look at it later

pez10:08:05

CLOSURE_DEFINES:

var CLOSURE_DEFINES = $CLJS.CLOSURE_DEFINES = {"shadow.cljs.devtools.client.env.repl_pprint":false,"shadow.cljs.devtools.client.env.devtools_url":"","shadow.cljs.devtools.client.env.autoload":false,"shadow.cljs.devtools.client.env.proc_id":"2cce7108-2ff9-43b0-9469-40d5785b5f80","goog.ENABLE_DEBUG_LOADER":false,"shadow.cljs.devtools.client.env.server_port":9631,"shadow.cljs.devtools.client.env.use_document_host":false,"shadow.cljs.devtools.client.env.module_format":"js","goog.LOCALE":"en","shadow.cljs.devtools.client.env.build_id":"calva","shadow.cljs.devtools.client.env.ignore_warnings":false,"goog.DEBUG":true,"shadow.cljs.devtools.client.env.ssl":false,"shadow.cljs.devtools.client.env.enabled":true,"shadow.cljs.devtools.client.env.server_host":"localhost","goog.TRANSPILE":"never"};

thheller10:08:25

"shadow.cljs.devtools.client.env.enabled":true

thheller10:08:51

so when the shadow.cljs.devtools.client.browser is loaded it should defiinitely do something

pez10:08:20

Maybe the TypeScript compiler optimizes it away?

thheller10:08:47

try just import "./lib/...."

pez10:08:32

Checked it. It didn’t optimize it away. Now will try with just import

thheller10:08:22

there is one suspicious thing: the 9631 port

thheller10:08:36

which means you probably have 2 shadow-cljs isntances running?

thheller10:08:13

might not be intentional and you are just connected to the wrong one?

pez10:08:46

I do have two instances running. The project I am testing my extesion with and then the watcher building the library/modules. I do not think I am connected to the wrong one.

pez10:08:38

I get SyntaxError: Unexpected token import when just importing. At runtime, the TS compiler seems to think it is dandy.

thheller10:08:41

did you try require instead yet?

pez10:08:26

I was talking shit. Had placed the import in the generated file…

pez10:08:39

The TS compiler rewrites it as require. (Yes, I did try the conditional require. It helps building the release build, but still this connection problem.)

pez10:08:00

But now using import (transcribed to require) I do get an error message with a hint, at last…

pez10:08:00

window not defined here: window.addEventListener("beforeunload",(function (){

thheller10:08:24

so I guess its really node then

thheller10:08:32

try adding :runtime :node in your build config

thheller10:08:42

and loading ...client.node instead of .browser

pez10:08:33

Thanks! Will try right away.

pez11:08:45

Now it connected! But running into a new problems

ReferenceError: SHADOW_NODE_EVAL is not defined
	at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/Users/pez/Projects/clojure4vscode/lib/shadow.cljs.devtools.client.node.js:62:14)

pez11:08:00

Line 62: var result = SHADOW_NODE_EVAL(js,source_map_json);

pez11:08:45

I placed :runtime :node in the target config, was that correct?

thheller11:08:36

yes. hmm sorry the .node stuff is not currently compatible with :npm-module

thheller11:08:41

I'll see about fixing that

thheller11:08:49

it currently assumes :node-libray or :node-script

pez11:08:13

I get very confused by the fact that I am using Calva for developing Calva. For Calva I use the built Calva extension, so maybe I need to build that and install before we conclude that things does not work…

😕 4
pez11:08:55

No, I get the same error.

pez11:08:01

I’ll package a release w/o the :runtime :node config for now. Do you think I can fix it in shadow-cljs and send you a PR, or is it expert level stuff?

thheller11:08:22

hmm I just checked the code and it should actually work

thheller11:08:05

ah no wait nevermind.

thheller11:08:58

I guess you can try and set global.SHADOW_NODE_EVAL = function(js, sm) { goog.globalEval(js); } before you load the .node ns

thheller11:08:16

ah no wait the goog. won't exist yet

thheller11:08:42

so try just global.SHADOW_NODE_EVAL = function(js, sm) { eval(js); }

thheller11:08:51

the problem itself isn't hard to fix

thheller11:08:05

the problem is identifying the platform correctly and then doing things in the correct order

thheller11:08:27

I don't know how the vscode or electron stuff executes exactly

thheller11:08:59

global.SHADOW_NODE_EVAL = function(js, smJson) {
  if (smJson) {
    js += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,";
    js += Buffer.from(smJson).toString('base64');
  }

  // console.log(js);

  return VM.runInThisContext.call(global, js,
    {filename: "<eval>",
     lineOffset: 0,
     displayErrors: true});
};

thheller11:08:27

you can also try just adding that. thats the default fn used by :node-script and :node-library

thheller11:08:46

VM is var VM = require("vm");

pez11:08:17

Now a new error:

ReferenceError: cljs is not defined
	at <eval>:2:1
	at <eval>:3:1078
	at ContextifyScript.Script.runInThisContext (vm.js:23:33)
	at runInThisContext (vm.js:95:38)
	at global.SHADOW_NODE_EVAL (/Users/pez/Projects/clojure4vscode/out/calva/extension.js:14:32)
	at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/Users/pez/Projects/clojure4vscode/lib/shadow.cljs.devtools.client.node.js:62:14)

thheller11:08:43

hmm yeah thought so. the VM part doesn't work

thheller11:08:49

try with direct eval instead

pez11:08:53

This should all go in the development conditional, right? (Not that I have gotten that one to work yet, but anyway.)

pez11:08:40

I need to go now. Will be back later today. Can’t express how much I appreciate all your help.

pez12:08:08

Curious, the SHADOW_EVAL function is called with the cljs code compiled to js as a result of nrepl carrying out the eval operation?

thheller12:08:51

its used to to eval the code created by the repl yes

pez15:08:46

Using eval directly gives the same error.

thheller15:08:56

hmm yeah the module isolation is tricky with this one

thheller15:08:45

do you know if the TS tools do something to the compiled CLJS code at all?

thheller15:08:05

or does it just copy the files along with its output?

pez15:08:29

The TS compiler never touches the CLJS generated code, I’m pretty sure.

Alex H15:08:11

hm, what's the flow to recompile individual files with the node-repl? Especially when e.g. I'm building a library, so don't really have an entry point that requires all the files I might want to load in the node-repl to try out

pez15:08:19

What I do is to build the cljs code toward a ‘/lib’ directory which is also symlinked to the /out directory where the TS compiler puts it stuff. Conceptually like so:

/out/calva/*.js (generated from *.ts)
/out/lib/*.js (generated from *.cljs)

pez15:08:10

I do the copying.

thheller15:08:13

@alex340 the common workflow is to load your code via load-file or (require 'that.ns :reload). Cursive has a keybind to load the current file in the REPL and thats what I use all the time. The command uses load-file but require also works.

Alex H15:08:38

I tried (require 'some.ns :reload), but that didn't seem to cause shadow-cljs to rebuild it

thheller15:08:11

hmm it should?

pez15:08:48

Rebuilds are not triggered by that, AFAIK, @alex340.

Alex H15:08:56

the file has an explicit typo in it, and yet

cljs.user=> (require 'verktyg.styled :reload)
nil

Alex H15:08:23

ok, so how are they triggered when using a repl-based flow?

pez15:08:34

Are you running a watcher on the code?

Alex H15:08:44

no, because I don't have any particular entry point

pez09:08:52

Hello. Sorry to bother with a noob question, but his has been puzzling me since yesterday 😃 Why does the lack of entry point prevent the use of a watcher? It seems there is something important for me to learn here.

Alex H15:08:55

it's just a collection of namespaces as part of a library

thheller15:08:05

they ARE supposed to be triggered by that. there does not need to be a watcher running for that.

thheller15:08:09

if its not thats a bug

thheller15:08:43

totally possible, not ruling that out. if you can reproduce it in a dummy project please report it

Alex H15:08:58

I can push this project. it's a bit of a mess, so didn't want to publish it yet, but w/e

Alex H15:08:15

or actually, maybe I can set a simpler dummy

thheller15:08:34

I can try myself in a bit. need to finish this post first. 😉

Alex H16:08:32

the package.json is a bit lazy, in that it contains irrelevant stuff (and so does the shadow-cljs.edn), but that's about it

thheller16:08:08

thx. will check it out.

pez16:08:33

@thheller: what is the :runtime config supposed to do? (I don’t find it mentioned in the docs.)

thheller16:08:04

decide which REPL client gets compiled

thheller16:08:17

@lilactown should maybe help with your CI issues

lilactown16:08:46

Replying so I remember to look later 😍

pez16:08:20

@thheller: that should mean that I can keep that part of the config even though it is not solving my problem right now, because when Calva is used “out there” it will be the REPL client of the particular projects that are in play and not the REPL client in the Calva extension?

pez16:08:59

Sorry if it is a stupid question, I meant what I said that using Calva for Calva development confuses me. 😃

thheller16:08:05

yes, user projects won't be affected

thheller16:08:22

its just your REPL while developing the calva for calva inception stuff 😛

pez16:08:43

Haha, thanks. I’ll try to remember that.

eoliphant23:08:14

anyone using antd with shadow?