I'm trying to install Growthbook for nodejs and ke...
# ask-questions
a
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
what nodeJs version are you using?
a
Hey Graham, I'm using v18.3.0
f
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
Should I try to downgrade my nodejs version ?
f
that would work - we're working on a solution
we want it to work with node 18
a
Ok so it works on node 16 ?
f
yes
a
Just tried running build
vite build
on node
v16.9.1
and got the same error. Any ideas what to try next ?
f
let me check my node version
a
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
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
Ok so should I downgrade my nodejs to v16 and and add
type: module
in my package.json ?
f
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
Yea using I'm using typescript too. I tried downgrading to 16.9.1 and still the same error
f
If you are able to downgrade Typescript to 4.6 or earlier that might work
a
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
no, they are very similar