https://www.growthbook.io/ logo
a

ambitious-crowd-69774

07/22/2022, 4:03 AM
I'm trying to install Growthbook for nodejs and keep getting this error:
SyntaxError: Named export 'GrowthBook' not found. The requested module '@growthbook/growthbook' is a CommonJS module, which may not support all module.exports as named exports.
Im testing this in a barebones sveltekit/typescript project and just by importing growthbook it throws this error at build time. This is my import - copied from docs:
Import { GrowthBook } from “@growthbook/growthbook”
This is a barebones, fresh sveltekit app I'm testing on. Runs fine during dev but fails at build. Does anyone have any ideas here ?
f

fresh-football-47124

07/22/2022, 4:03 AM
what nodeJs version are you using?
a

ambitious-crowd-69774

07/22/2022, 4:07 AM
Hey Graham, I'm using v18.3.0
f

fresh-football-47124

07/22/2022, 4:07 AM
ya, you found the other thread with that problem
I'm not an expert at node versions, but I understand this is a problem
a

ambitious-crowd-69774

07/22/2022, 4:08 AM
Should I try to downgrade my nodejs version ?
f

fresh-football-47124

07/22/2022, 4:09 AM
that would work - we're working on a solution
we want it to work with node 18
a

ambitious-crowd-69774

07/22/2022, 4:10 AM
Ok so it works on node 16 ?
f

fresh-football-47124

07/22/2022, 4:10 AM
yes
a

ambitious-crowd-69774

07/22/2022, 4:21 AM
Just tried running build
vite build
on node
v16.9.1
and got the same error. Any ideas what to try next ?
f

fresh-football-47124

07/22/2022, 4:21 AM
let me check my node version
a

ambitious-crowd-69774

07/22/2022, 4:28 AM
Sveltekit is a server side rendered app. Could I send the client the growthbook features and experiments from the server, or does the tracking callback need to be called on the client for Mixpanel tracking to work ?
f

future-teacher-7046

07/22/2022, 4:28 AM
It's an issue with Node's ESM support. That was enabled by default on version 18, but can be opted in for earlier Node versions, which is likely what you are doing. I think our SDK only works in Node when using CommonJS module resolution. We're working on a fix to support ESM with node
a

ambitious-crowd-69774

07/22/2022, 4:31 AM
Ok so should I downgrade my nodejs to v16 and and add
type: module
in my package.json ?
f

future-teacher-7046

07/22/2022, 4:32 AM
are you using Typescript as well? We're still debugging the exact cause, but it might be a conflict with typescript and node versions. I'm not sure just downgrading node alone will fix it
a

ambitious-crowd-69774

07/22/2022, 4:33 AM
Yea using I'm using typescript too. I tried downgrading to 16.9.1 and still the same error
f

future-teacher-7046

07/22/2022, 4:35 AM
If you are able to downgrade Typescript to 4.6 or earlier that might work
a

ambitious-crowd-69774

07/22/2022, 4:36 AM
Ok I will test this out in the morning. Thank you for your help 💯
Update: just tried downgrading TS and node and still had the same error… I'll just use the browser import. Is there anything majorly different from the browser cdn version and the node version ?
f

fresh-football-47124

07/22/2022, 4:55 AM
no, they are very similar
34 Views