I have a builder content page that contains an Image block configured to load an image from our public Shopify CDN using data binding.
This is a Next.js site, and when I run it locally with Builder.io configured to point to my localhost the image is rendered correctly.
When I configure Builder.io to aim at my Vercel hosting path and I push my code to bitbucket, Vercel runs a build and deployment. The subsequent rendered page does not render the image.
Builder content link
Builder public api key
a47041ecd8824aa2b0ead02a0b338b76
What are you trying to accomplish
I have an image block that should render an image via data binding, the image resides on our Shopify CDN.
When I have builder configured for my localhost:3000 and run locally it works fine.
When I push my updates to Vercel and reconfigure builder to point at vercel, the image doesn’t load
Code stack you are integrating Builder with
Next.js, React, hosted at Vercel, referencing an image on our public CDN
More Info
In the Chrome Browser Debug Console, the Vercel page load shows no console errors, nor does it show non-200 results for assets in the Network tab - the image is never requested when the site loads via Vercel.
I’ve spent some time trying to reproduce this issue on my end but haven’t had any luck. I’ve seen a similar issue with data bindings (not specifically with Vercel) where the logic would run before the element was on the page, so once the element was loaded the binding (like style.color or component.options.image) already ran, so it wouldn’t get run again.
In the past this has been resolved by adding an additional binding of showIf Builder.isBrowser (or adding it directly to the image binding). Could you try this out and let me know if it makes a difference on the Vercel path? If not, we can continue to try and reproduce and dig in further.
I did notice Vercel stripping out one of the dependencies that allow Builder’s sdk to run bindings on the server, ( only in SSG, but not on first render, only on revalidation, which is probably why you see it working sometimes after a fresh build, or on localhost) , if that’s the case, I’d import the dependency manually:
Then in your page code ( could be pages/[[...page]].jsx):
// outside any function/component body
import { Builder } from '@builder.io/sdk'
if (Builder.isServer) {
try {
// tricking whatever stripping vm2 to include it on server
require('vm2');
} catch(e) {
console.error(e)
}
}
Thanks for putting your eyes on this problem @aziz!
The second section of code breaks my builds due to webpack errors. When I include it I get this build error:
knack-billboard git:(main) ✗ npm run build
> knack-billboard@0.1.0 build
> next build
info - Checking validity of types
warn - No ESLint configuration detected. Run next lint to begin setup
info - Creating an optimized production build
Failed to compile.
./node_modules/vm2/lib/nodevm.js
Module not found: Can't resolve 'fs' in '/Users/soultech67/projects/knack-billboard/node_modules/vm2/lib'
Import trace for requested module:
./node_modules/vm2/lib/main.js
./node_modules/vm2/index.js
./pages/[[...page]].tsx
./node_modules/vm2/lib/resolver-compat.js
Module not found: Can't resolve 'fs' in '/Users/soultech67/projects/knack-billboard/node_modules/vm2/lib'
Import trace for requested module:
./node_modules/vm2/lib/nodevm.js
./node_modules/vm2/lib/main.js
./node_modules/vm2/index.js
./pages/[[...page]].tsx
./node_modules/vm2/lib/resolver-compat.js
Module not found: Can't resolve 'module' in '/Users/soultech67/projects/knack-billboard/node_modules/vm2/lib'
Import trace for requested module:
./node_modules/vm2/lib/nodevm.js
./node_modules/vm2/lib/main.js
./node_modules/vm2/index.js
./pages/[[...page]].tsx
./node_modules/vm2/lib/resolver-compat.js
Module not found: Can't resolve 'async_hooks' in '/Users/soultech67/projects/knack-billboard/node_modules/vm2/lib'
Import trace for requested module:
./node_modules/vm2/lib/nodevm.js
./node_modules/vm2/lib/main.js
./node_modules/vm2/index.js
./pages/[[...page]].tsx
./node_modules/vm2/lib/resolver.js
Module not found: Can't resolve 'fs' in '/Users/soultech67/projects/knack-billboard/node_modules/vm2/lib'
Import trace for requested module:
./node_modules/vm2/lib/resolver-compat.js
./node_modules/vm2/lib/nodevm.js
./node_modules/vm2/lib/main.js
./node_modules/vm2/index.js
./pages/[[...page]].tsx
> Build failed because of webpack errors
I’m curious, when you state that you notice Vercel is stripping out one of the dependencies - where are you observing this? I ran on localhost and inspected the debug console using the Chrome Debugging Tools. Looking at the Sources tab and Network tab I don’t see vm2 listed.