Issue with Next/Script in NextJS 13 app router

118 Views Asked by At

I want to execute a script from the public directory. However, no matter how I pass the src to , it returns 404 error, indicating that the file does not exist, although the file exists in the public directory.

Here is a very simple example:

    const Home: NextPage = async () => {

     return (
      <>
       <Script src="/static/example.js" />

       <HomePage />
      </>
    );
   };

   export default Home;

Does anyone know how to handle this issue? I am using next version 13.5.3

1

There are 1 best solutions below

1
On

try to wrap the Script component with Head component from "next/document"