how can import js file in head script of nuxt 3 configs?

79 Views Asked by At

this is my error enter image description here

i tried this ways and plugins doesn't work

{
  type: "text/javascript",
  src: "~/assets/js/kit.fontawesome.js",
},
{
  type: "text/javascript",
  src: "assets/js/kit.fontawesome.js",
},
{
  type: "text/javascript",
  src: "@/assets/js/kit.fontawesome.js",
},
{
  type: "text/javascript",
  src: "js/kit.fontawesome.js",
},
1

There are 1 best solutions below

0
On

You can use useHead on .vue page as well. But it should be the same as you do. But if anyone else is interested:

<script setup>
    useHead({
        title: "Some title",
        script: [
            {
                src: "/_nuxt/assets/test.js",
            },
        ],
    });
</script>

The problem though you are facing is you are using wrong path. You need to use public path as I did in my example.

Or better, you can put your file into public folder let's say test.js file inside this folder will become src: "/test.js".