Hi guys! I’m having some package/module issues using the SDK in node (for a backend service). I’ve s...
j

Jacob Tallberg

almost 3 years ago
Hi guys! I’m having some package/module issues using the SDK in node (for a backend service). I’ve setup a typescript project, installed a bunch of dependencies and everything works (including building the app with tic) except loading the growthbook sdk at runtime. I’m getting the following error:
import { GrowthBook } from "@growthbook/growthbook";
     ^^^^^^^^^^
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.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@growthbook/growthbook';
const { GrowthBook } = pkg;
My IDE (Vscode) has no problem loading the sdk as an ES6 module. No other libs are causing any issues loading them with import. Just to humor node, I tried the suggestion and got the following error:
(node:20837) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Users/xxxx/node_modules/@growthbook/growthbook/dist/esm/index.js:1
export { GrowthBook } from "./GrowthBook";
^^^^^^

SyntaxError: Unexpected token 'export'
  at Object.compileFunction (node:vm:352:18)
  at wrapSafe (node:internal/modules/cjs/loader:1033:15)
  at Module._compile (node:internal/modules/cjs/loader:1069:27)
  at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
  at Module.load (node:internal/modules/cjs/loader:981:32)
  at Module._load (node:internal/modules/cjs/loader:827:12)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
My tsconfig.json is as follows
{
 "compilerOptions": {
  "target": "ES2022",
  "module": "es6",
  "lib": ["ES2022", "dom"],
  "moduleResolution": "node",
  "rootDir": ".",
  "outDir": "build",
  "allowSyntheticDefaultImports": true,
  "importHelpers": true,
  "alwaysStrict": true,
  "sourceMap": true,
  "forceConsistentCasingInFileNames": true,
  "noFallthroughCasesInSwitch": true,
  "noImplicitReturns": true,
  "noUnusedLocals": true,
  "noUnusedParameters": true,
  "noImplicitAny": false,
  "noImplicitThis": false,
  "strictNullChecks": false
 },
 "include": ["src/**/*", "__tests__/**/*"]
}
Versions: • `node`: 18.3.0 • `@growthbook/growthbook`: 0.18.0 • `tsc`: 4.7.2 Cmd to build is
tsc -p tsconfig.json
Cmd to run
node build/src/main.js
I spent a good deal of time yesterday trying to figure out the issue but to no avail. Any ideas/suggestions are much appreciated!
Simple Deployment to Kubernetes using `nginx-ingress` and `cert-manager` - just sharing here ```api...
j

Julian Alves

over 3 years ago
Simple Deployment to Kubernetes using
nginx-ingress
and
cert-manager
- just sharing here
apiVersion: apps/v1
kind: Deployment
metadata:
  name: growthbook-web
  labels:
    app: growthbook-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: growthbook-web
  template:
    metadata:
      labels:
        app: growthbook-web
    spec:
      containers:
        - name: growthbook-web
          image: growthbook/growthbook:latest
          env:
            - name: APP_ORIGIN
              value: <https://growthbook>.<DOMAIN_NAME>
            - name: API_HOST
              value: <https://growthbook-api>.<DOMAIN_NAME>
            - name: MONGODB_URI
              value: <mongodb://root:password@growthbook-mongo.default:27017>
          ports:
            - containerPort: 3000
              name: web
            - containerPort: 3100
              name: api
---
apiVersion: v1
kind: Service
metadata:
  name: growthbook-web
spec:
  ports:
    - name: web
      port: 3000
      targetPort: 3000
    - name: api
      port: 3100
      targetPort: 3100
  selector:
    app: growthbook-web
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: growthbook-mongo
  labels:
    app: growthbook-mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: growthbook-mongo
  template:
    metadata:
      labels:
        app: growthbook-mongo
    spec:
      containers:
        - name: growthbook-mongo
          image: mongo:latest
          env:
            - name: MONGO_INITDB_ROOT_USERNAME
              value: root
            - name: MONGO_INITDB_ROOT_PASSWORD
              value: password
          ports:
            - containerPort: 27017
---
apiVersion: v1
kind: Service
metadata:
  name: growthbook-mongo
spec:
  ports:
    - name: web
      port: 27017
      targetPort: 27017
  selector:
    app: growthbook-mongo
  type: ClusterIP
---
apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: Ingress
metadata:
  annotations:
    <http://cert-manager.io/cluster-issuer|cert-manager.io/cluster-issuer>: letsencrypt
    <http://nginx.ingress.kubernetes.io/proxy-connect-timeout|nginx.ingress.kubernetes.io/proxy-connect-timeout>: "300"
    <http://nginx.ingress.kubernetes.io/proxy-read-timeout|nginx.ingress.kubernetes.io/proxy-read-timeout>: "300"
    <http://nginx.ingress.kubernetes.io/proxy-send-timeout|nginx.ingress.kubernetes.io/proxy-send-timeout>: "300"
  labels:
    app: growthbook-web
  name: growthbook-web
spec:
  ingressClassName: nginx
  rules:
    - host: growthbook.<DOMAIN_NAME>
      http:
        paths:
          - backend:
              service:
                name: growthbook-web
                port:
                  name: web
            path: /
            pathType: ImplementationSpecific
  tls:
    - hosts:
        - growthbook.<DOMAIN_NAME>
      secretName: growthbook-letsencrypt
---
apiVersion: <http://networking.k8s.io/v1|networking.k8s.io/v1>
kind: Ingress
metadata:
  annotations:
    <http://cert-manager.io/cluster-issuer|cert-manager.io/cluster-issuer>: letsencrypt
    <http://nginx.ingress.kubernetes.io/proxy-connect-timeout|nginx.ingress.kubernetes.io/proxy-connect-timeout>: "300"
    <http://nginx.ingress.kubernetes.io/proxy-read-timeout|nginx.ingress.kubernetes.io/proxy-read-timeout>: "300"
    <http://nginx.ingress.kubernetes.io/proxy-send-timeout|nginx.ingress.kubernetes.io/proxy-send-timeout>: "300"
  labels:
    app: growthbook-api
  name: growthbook-api
spec:
  ingressClassName: nginx
  rules:
    - host: growthbook-api.<DOMAIN_NAME>
      http:
        paths:
          - backend:
              service:
                name: growthbook-web
                port:
                  name: api
            path: /
            pathType: ImplementationSpecific
  tls:
    - hosts:
        - growthbook-api.<DOMAIN_NAME>
      secretName: growthbook-api-letsencrypt
🙌 1