close

[Solved] Next.js Loads script tags but it doesn’t execute them

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Next.js Loads script tags but it doesn’t execute them in nextjs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve Next.js Loads script tags but it doesn’t execute them Error ?

  1. How To Solve Next.js Loads script tags but it doesn't execute them Error?

    To Solve Next.js Loads script tags but it doesn't execute them Error just Create a folder for your static files. <root>/static/hello.js in your index.js <root>/pages/index.js

  2. Next.js Loads script tags but it doesn't execute them

    To Solve Next.js Loads script tags but it doesn't execute them Error just Create a folder for your static files. <root>/static/hello.js in your index.js <root>/pages/index.js

Solution 1

Create a folder for your static files:

<root>/static/hello.js

in your index.js

<root>/pages/index.js

import Head from 'next/head';
import MyAwesomeComponent from '../components/mycomponent';

export default () => (
  <div>
    <Head>
      <script type="text/javascript" src="/static/hello.js"></script>
    </Head>
    <MyAwesomeComponent />
  </div>
)

Solution 2

You can also run js code this

          <script
            dangerouslySetInnerHTML={{
              __html: `
                      let a = 1;
                      functionCall();
                  `,
            }}
          ></script>

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment