workerLogger.js: Cannot find module 'branch-sdk' in 'public/pages/cjg9.js'; trying to install branch-sdk via NPM packages

Steps to reproduce:
installed ‘branch-sdk’ via NPM

Then I install the Branch SDK via NPM (I think?)

it seems like it installs

NOW, in my code I import & try to init it:


import branch from 'branch-sdk'

$w.onReady(function () {
    console.log("branch is", branch)
    console.log("INITIALIZING BRANCH...")
    branch.init('XYZ', function(err, data) {
       console.log(" BRANCH INIT CALLBACK ..." , err, data);
})

When publishing the site, I get
workerLogger.js:103 Cannot find module ‘branch-sdk’ in ‘public/pages/cjg9.js’

Although I’m an experienced JS developer, I’ve only been using Wix for a little over a month. What I don’t understand is two things :

  1. is this only available from “backend”? That’s fine— I can use it on the backend, but I don’t know how o make it backend-only. I just installed it into the NPM section and I see comments on the forums about using NPM packages on either the front or back but I don’t understand how to switch the package from one to the other. if this is because it is ‘back-end’ only, how do I switch it to run only in the backend? (it would be super helpful if Wix told me “you are trying to run a backend only NPM package on the front end instead of the cryptic error message.”)

  2. Does wix keep an ‘approved’ list of NPM packages as the docs suggest? If so, I assume if it came up in the Wix selection interface (above) it is ‘approved’?

thank you in advance.

try moving the branch-sdk call exclusively to the backend. ‘backend-only’ - call it from code under the Backend/ folder.

public/ is shared between front and backend.

This cleared everything up for me: https://support.wix.com/en/article/velo-where-do-i-put-my-code, particularly the section marked “Backend File Types”. although I still can’t seem to call a back-end function from the front using await , I can get these .jsw (web modules) to work from the front-end using the .then() syntax

@jason26653 Using await should actually be a bit easier. Can you give an example of both types of calls? Maybe I can spot what your problem is.

@yisrael-wix – yes i moved it to backend (JSW) web module code and Here’s what I got:

please see https://www.wix. com/velo/forum/coding-with-velo/error-loading-web-module-backend

Did you succesfully integrate branch io sdk on wix? Can you share the steps?

Pretty late to the party but heres a working branch-sdk integration using Wix custom elements:

We can’t use Branch SDK on a wix page because it uses DOM specific functionality but you can use it on a custom element and send whatever data you may need between the page and custom element to perform branch-sdk functions on the custom element

In my case I’m just using it to get the link data when a user visits the site from a deep link. I’m using a node.js server to create the links