#JavaScript script won't run in PRD

97 messages · Page 1 of 1 (latest)

velvet canopy
runic tundra
#

x D

#

without it astro is hoisting ( moving it all into one file if the file isnt too big )

#

and its creating an error which basically stopping the whole script

#

in dev the script tags raent optimized yet

velvet canopy
#

Not that one 😄

#

oh wait

#

what?

#

that isnt the script im talking about tho?

runic tundra
#

in basehead

#

try adding the is:inline

#

then to see the production build locally you can pnpm build && pnpm preview

velvet canopy
#

that stops running it in dev now lol

runic tundra
#

well thats crazy

velvet canopy
#
        <script is:inline>
            import TypeIt from "typeit";

            new TypeIt("#header", {
                strings: "鬼 0niSec",
                loop: true,
            })
                .go()
                .pause(1500);
        </script>
#

this script

#

Just so im clear lol

runic tundra
#

noo

#

in basehead put it on line 18

#

you can import from nodemodules in an inline script because astro wont process it btw

#

cant***

velvet canopy
#

oooooooooooooooooo

#

yeah that did it

runic tundra
#

🎉

velvet canopy
#

Lol is it a 🐛 if I'm just an idiot?

#

Asking for a friend >.>

runic tundra
#

haha nah that is a very niche error

#

not an idiot at all that wouldve stumped a lot of people

#

the error in console about the widget was a hint though

velvet canopy
#

what mean this

#

downloadable font: no supported format found (font-family: "Fira Code" style:normal weight:400 stretch:100 src index:1) source: (end of source list)

#

and that

severe prism
#

There's a CORS error originating from the hoisted.js file. Pretty sure that's the file containing the TypeIt code. My guess would be that's the reason

runic tundra
velvet canopy
#

It's being used and rendered so it def is

runic tundra
#

should make a new support thread tbh lol

velvet canopy
runic tundra
#

so others can help there because ive never used fonts

velvet canopy
#

for SSG

runic tundra
#

that error was coming from not having is:inline

velvet canopy
#

ahhhh

runic tundra
#

identity widget needed to be coming from the root page not from a different file

severe prism
#

Sorry, I just noticed you were already discussing the cors error 😅

#

first hit on google is Astro related haha. Oliver's solution is suggested there as well https://answers.netlify.com/t/cors-error-with-identity-widget-on-deployed-website/75484

Netlify Support Forums

Hi there, I’ve recently built a portfolio website with Astro and I’ve implemented Netlify CMS using the custom configuration mentioned on the docs and it works as intented. However, I’m running into an issue where the identity widget is displaying a CORS issue in the console: Access to script at 'https://identity.netlify.com/v1/netlify-identit...

severe prism
velvet canopy
#

That's prefetch right?

severe prism
#

It's called preload on the link tag, but same thing

velvet canopy
#

hm, still getting it after setting prefetch to just hover

#

weird

#

ill fix it later

#

not doing that on this branch

severe prism
#

Oh sorry, it's not the astro prefetching

velvet canopy
#

ohhhh

#

what is it lol

severe prism
#

It's this tag in your head <link rel="preload" href="/fonts/firacode-regular.ttf" as="font" type="font/ttf" crossorigin="">

velvet canopy
#

ooooooooooo

#

duh

severe prism
#

That being said I'm not sure why it's complaining because it seems to be used in the style tag in the head 🤷‍♂️ These warnings can be a bit mysterious sometimes

velvet canopy
#

Do I import the module in BaseHead in the script?

runic tundra
#

wym sorry

velvet canopy
#

It still won't work in prd when built lol

#

The TypeIt script

velvet canopy
#

So I did that just now (didn't push) and it still isn't working lol

runic tundra
#

i pulled and tried it

#

seems working

#

im saying the netlify indeitfy script on line 30

#

the line i linked

velvet canopy
#

No not that one haha

#

The TypeIt JS

runic tundra
#

yes i know

#

remember because when that one doesnt have is inline

#

it creates an error in browser

velvet canopy
#

Import declarations may only occur at top level in browser

#

So where do I import lol

runic tundra
#

no

#

on line 30

#

add is:inline

#

just like in the picture

#

to the netlify indentify script

velvet canopy
#

Yep isn't working locally

runic tundra
#

and that will fix the typeit script

#

can you copy paste your basehead file

velvet canopy
#
---
// Import the global.css file here so that it is included on
// all pages through the use of the <BaseHead /> component.
import "../styles/global.css";

interface Props {
    title: string;
    description: string;
    image?: string;
}

const canonicalURL = new URL(Astro.url.pathname, Astro.site);

const { title, description, image = "/blog-placeholder-1.jpg" } = Astro.props;
---

<!-- TypeIt JS -->
<script is:inline>
    import TypeIt from "typeit";

    new TypeIt("#header", {
        strings: "鬼 0niSec",
        loop: true,
    })
        .go()
        .pause(1500);
</script>

<!-- Netlify Identify -->
<script
    src="https://identity.netlify.com/v1/netlify-identity-widget.js"
    is:inline></script>

<!-- Global Metadata -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />

<!-- Font preloads -->
<link
    rel="preload"
    href="/fonts/firacode-regular.ttf"
    as="font"
    type="font/ttf"
    crossorigin
/>

<!-- Canonical URL -->
<link rel="canonical" href={canonicalURL} />

<!-- Primary Meta Tags -->
<title>{title}</title>
<meta name="title" content={title} />
<meta name="description" content={description} />

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={new URL(image, Astro.url)} />

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:title" content={title} />
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image, Astro.url)} />
runic tundra
#

yes

#

do not add is:inline to the typeit

velvet canopy
#

ohhhh

runic tundra
#

only add it do netlify identify

#

because when it is inline it cannot bundle from node modules

velvet canopy
#

Oooookay, that did it lmao

#

ty again sir