#Netlify defer scripts GET error

18 messages · Page 1 of 1 (latest)

crystal flower
#

Hey guys, I have a weird bug on my site when I deploy my Astro site to Netlify. When I use npm run dev, all of my site's JS works.

But when I deploy my site to Netlify through GitHub, my site's JS references which do not use the defer attribute are loading perfectly fine.

However, the ones that have the defer attribute fail to load on the deployed site! They have the following error:

GET[https://www.alieninsectbass.com/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js](https://www.alieninsectbass.com/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js "https://www.alieninsectbass.com/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js")[HTTP/2 404 9ms]  

GET[https://www.alieninsectbass.com/src/scripts/tooltips.js](https://www.alieninsectbass.com/src/scripts/tooltips.js "https://www.alieninsectbass.com/src/scripts/tooltips.js")[HTTP/2 404 9ms]  

GET[https://www.alieninsectbass.com/src/scripts/searchfunctions.js](https://www.alieninsectbass.com/src/scripts/searchfunctions.js "https://www.alieninsectbass.com/src/scripts/searchfunctions.js")[HTTP/2 404 9ms]

I need the defer attributes on those three scripts because otherwise my code throws a vite error that causes my entire site to crash.

Can someone help me fix this?

crystal flower
#

Please I need help on this D; I removed the defer attributes from the tooltip.js and searchfunctions.js, but I could not remove it from the bootstrap script link otherwise I got an error

warm tartan
#

Is it at all possible for you to share your code publicly? Through github or the like? If not that's fine, my initial guess is though that bootstrap is to blame.

crystal flower
warm tartan
#

I think what might be happening is that bootstrap isn't being built properly as it doesn't seem to exist, hence the 404 error. Let me see your Layout, for clarity and also your build script.

crystal flower
#

Ok one sec gimme a little bit currently in a meeting, will get back to you

warm tartan
#

Take your time 😉

#

When you get a chance to get to this, do me a favor and run a build as well and provide the output of the build and see if those files physically exist in those locations.

#

I can't believe I didn't see this initially but it appears that the paths are wrong too. Every reference should be scoped to the dist directory, so instead of...

GET[https://www.alieninsectbass.com/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js](https://www.alieninsectbass.com/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js "https://www.alieninsectbass.com/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js")[HTTP/2 404 9ms]  

it should be...

GET[https://www.alieninsectbass.com/js/bootstrap.bundle.min.js](https://www.alieninsectbass.com/js/bootstrap.bundle.min.js "https://www.alieninsectbass.com/js/bootstrap.bundle.min.js")[HTTP/2 404 9ms]  

At least I think this is right, another opinion would be helpful, I've just started with this framework.

crystal flower
#

OOF let me try this out! Still in a meeting but if this is correct you're a lifesaver! 🍬

crystal flower
#

I tried your suggestion of changing the script tag and it didn't work

crystal flower
#

nvm npm run build

#

No errors when running the build

crystal flower
#

FIXED IT! I added the following line to the code inside the top --- ---:

import bootstrap from "bootstrap/dist/js/bootstrap.bundle.min.js?url";

...and changed the script to:

<script src={bootstrap} defer></script>
#

This fixed my issues. Folks, if you want to import Bootstrap via NPM to an Astro project, this is the way to do it!

warm tartan
#

I'm glad you got there and sorry I dissapeared for a couple days, I'm in the middle of a move.