nuxt-svgo-loader icon indicating copy to clipboard operation
nuxt-svgo-loader copied to clipboard

Usage outside of Vue Components

Open digitalkaoz opened this issue 1 year ago • 2 comments

im having trouble using this in None-Vue-Code (still nuxt3 but on the serverside)

import Logo from "~/assets/logo.svg?raw"

export default defineEventHandler(async (event) => {
  //do something with the logo here
}

the error im getting:

 ERROR  Error: Could not load /.../assets/logo.svg?raw (imported by model/pdf.ts): ENOENT: no such file or directory,  open '/.../assets/logo.svg?raw'

so i guess the loader is not active everywhere? i guess it should?

doing the same in a vue component works flawless!

using a different loader technique (none in this case):

import Logo from "~/assets/logo.svg"
WARN  (inject plugin) rollup-plugin-inject: failed to parse /.../assets/logo.svg. Consider restricting the plugin to particular files via options.include                                                                                                                                                           10:26:40 PM


 ERROR  RollupError: Expression expected (Note that you need plugins to import files that are not JavaScript)                                                                                                                                                                                                                                           nitro 10:26:40 PM


1: <svg xmlns="http://www.w3.org/2000/svg" width="280" height="186" fill="none"><path fill="#0C4A6E" d="M20.25 175.65c.9...
   ^

digitalkaoz avatar Mar 30 '24 21:03 digitalkaoz

i have a feeling its linked to https://github.com/jpkleemans/vite-svg-loader/pull/117 ?

digitalkaoz avatar Mar 30 '24 21:03 digitalkaoz

I'm thinking this issue might be tied to the nitro server, which seems to struggle with importing file types like .png and .svg. If we're looking to work with raw files on the server, it might be a good idea to look into using a file system package, such as fs or fs-extra.

Mini-ghost avatar Apr 01 '24 07:04 Mini-ghost