this is a follow-up to
www.wix. com/velo/forum/coding-with-velo/workerlogger-js-cannot-find-module-branch-sdk-in-public-pages-cjg9-js-trying-to-install-branch-sdk-via-npm-packages
however, you do not need to read that to understand the context here.
I have read and think I understand everything in this helpful but slightly difficult-to-find doc support.wix. com/en/article/velo-where-do-i-put-my-code
(when I say slightly difficult-to-find doc I mean currently it ranks Google #4 for the keyword “wix where do I put my code” even though you’d think this would be #1)
I am trying to use the NPM www.npmjs. com/package/branch-sdk to call a remote API via a backend call.
In my Main Pages, I have a file called simply example
this file is a blank page with this code
import {constructBranchURL} from "backend/constructBranchURL.jsw"
$w.onReady(function () {
const branchResponse = constructBranchURL().then((resp) => {
console.log("branch is", resp)
})
});
Under Code Files > Packages > NPM, I was able to successfully add the branch-sdk package
Now, the package branch-sdk appears installed under NMP in the sublist of Packages.
backend/constructBranchURL.jsw looks like so:
import branch from 'branch-sdk';
console.log("branch is", branch)
export function constructBranchURL() {
console.log(" hello world ..." );
branch.init('key_live_OUR_KEY_GOES_HERE', function(err, data) {
console.log("callback")
})
}
When I run this page, it looks like the backend has an error, which I can only see in Wix (not in the browser console) using Site Monitoring > Site Events
Looks like it just can’t load branch-sdk:
"jsonPayload":{
"message":"["Error loading web module backend/constructBranchURL.jsw: Cannot find module '/dynamic-modules/third-party-npm/facf9043/WC_BEGIN/branch-sdk/2.53.1/WC_END/branch-sdk/dist/build.min.js'. Please verify that the package.json has a valid \"main\" entry"]"
}
I believe the NPM package here is github. com/BranchMetrics/web-branch-deep-linking-attribution/blob/master/package.json , which does does seem to me to have a “main” entry.
Any tips on what to do next?
Also, are the packages I see in the Wix NPM “add NPM package” dashboard all approved? If so, I wonder why this seems to not load.