Fork me on GitHub
#shadow-cljs
<
2022-11-21
>
coltnz04:11:52

Hi, I'm requiring a node lib in package.json thusly:

"dependencies": {
  "pgsql-parser": "^13.4.0",
requiring it:
(:require
  ["pgsql-parser" :as pgsql]
but when I go to build my own node lib I get:
Uncaught Error: Cannot find module 'pgsql_parser'

coltnz04:11:19

Looking at the shim generated I see:

goog.provide("shadow.js.shim.module$pgsql_parser");
goog.provide("module$shadow_js_shim_module$pgsql_parser");
shadow.js.shim.module$pgsql_parser = require("pgsql_parser");
module$shadow_js_shim_module$pgsql_parser.default = shadow.js.shim.module$pgsql_parser;

coltnz04:11:56

If I edit to :

shadow.js.shim.module$pgsql_parser = require("pgsql-parser");

coltnz04:11:19

All is well. I assume this a bug to raise, but thought I'd check if anyone has an insight because this confuses me. The Shadow code calls Closure libs to generate names.

thheller06:11:16

@coltnz I don't know how that would happen? there is never any translation or conversion of - to _ for JS packages. I cannot reproduce it locally either? which shadow-cljs version do you use?

coltnz06:11:20

• shadow-cljs - server version: 2.20.10

coltnz06:11:36

It really is weird, I tried react-dom package and it is fine

thheller06:11:06

do you maybe have a [pgsql_parser :as pgsql] or [pgsql-parser :as pgsql] require somewhere else in your code?

thheller06:11:22

symbols might get translated, so use strings always for npm packages

coltnz07:11:49

Nope only the require as above. My build target is a node lib btw.

thheller07:11:17

build target shouldn't matter for this. just tried with :node-script and :node-library. both totally fine

qqq09:11:37

for shadow-cljs, for (shadow/watch :app-id), is it possible to say: you don't have to do highest level optimization, but please do a quick tree shake and output a .js that I can copy/paste elsewhere? [I'm working on a project involving both cljs and non-cljs js partts, and I'd like to copy/paste the generate .js file elsewhere]

thheller19:11:40

:advanced is the only thing doing the DCE, so no there is no alternative

qqq09:11:46

(shadow/release :app-id) takes ~20 seconds

qqq10:11:32

I have a file src/foo.js . Is there a way to tell shadow-cljs, even in optimizations:advanced, to not rewrite file src/foo.js ?

thheller19:11:05

no. why would that matter? if you want to prevent renaming of certain stuff add externs

henryw37411:11:26

I am setting a variable like this (set! js/Foo bar) and getting a warning `

constant Foo assigned a value more than once.
Original definition at externs.shadow.js:4
` what's the right thing to do here?

thheller19:11:18

what exactly are you trying to do there? you shouldn't really use set! if you want to export a global? use (js/goog.exportSymbol "Foo" bar) instead

👍 1