BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.98k stars 428 forks source link

[🐞] Partytown throwing 404 on the live site #619

Open renukote opened 2 weeks ago

renukote commented 2 weeks ago

Describe the bug

I'm using partytown version ^0.10.2 in my Gatsy project to load GTM and Netlify to host the repo. Everything works fine in preview deployments but as soon as I make it live, partytown call in the network tab throws 404.

Screenshot from live site Screenshot from 2024-08-31 16-41-28

Screenshot from deployment preview Screenshot from 2024-08-31 16-37-16

I'm loading all the lib files in gatsby-node.js as suggested in https://partytown.builder.io/gatsby

I tried using both onPreBuild and onPreBootstrap but the output is the same. I tried it twice on the production site and reverted it.

Here is the code from my project

gatsby-node.js

exports.onPreBuild = async () => {
  await copyLibFiles(path.join(__dirname, 'static', '~partytown'));
};

gatsby-ssr.js (inside onRenderBody)

  setHeadComponents([
    <Partytown key="partytown" forward={['dataLayer.push', 'gtag']} />,
    <script key="google-analytics" type="text/partytown" src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GOOGLE_TAGMANAGER_ID}`} />,
    <script
      key="google-analytics-config"
      type="text/partytown"
      // eslint-disable-next-line react/no-danger
      dangerouslySetInnerHTML={{
        __html: `window.dataLayer = window.dataLayer || [];
            window.gtag = function gtag(){ window.dataLayer.push(arguments);}
            gtag('js', new Date()); 
            gtag('config', '${process.env.GOOGLE_TAGMANAGER_ID}', { send_page_view: false })`
      }}
    />
  ]);

package.json (inside dependencies) "@builder.io/partytown": "^0.10.2",

Am I missing something here?

Reproduction

-

Steps to reproduce

Browser Info

Chromium

Additional Information

No response

renukote commented 2 weeks ago

image

Since it's showing partytown library is not being found, I also tried manually pushing all the lib files into the static folder and deployed it to live to see if that resolves the issue. Even that didn't work. I got the above error in the console.

image