oslllo / svg-fixer

Converts SVG Strokes To Fill.
https://docs.oslllo.com/svg-fixer/master/
MIT License
208 stars 16 forks source link

Error importing #86

Closed colemaring closed 1 year ago

colemaring commented 1 year ago

Could not find a declaration file for module 'oslllo-svg-fixer'. 'c:/Users/username/Desktop/projectName/node_modules/oslllo-svg-fixer/src/index.js' implicitly has an 'any' type. Try npm i --save-dev @types/oslllo-svg-fixer if it exists or add a new declaration (.d.ts) file containing declare module 'oslllo-svg-fixer';

I am a beginner at javascript and am confused by this error when importing this library. I haven't gotten this error importing any other javascript libraries and have been stuck on this for a few days.

I tried what it suggested and no luck..

Ghustavh97 commented 1 year ago

Hi, @colemaring this is a typescript error, this package does not have any type declarations yet so to fix your error simply add this before the line of your import:

// @ts-ignore
import SVGFixer from "oslllo-svg-fixer"

or use require

const SVGFixer = require('oslllo-svg-fixer')
colemaring commented 1 year ago

I am unsure why I am getting typescript errors as I used vite to build my project and selected vanilla javascript. I also tried not using vite and had the same issue.

Using require I get a "require is not defined" error in the console.

Thank you for your quick reply, I hope this information helps.

Ghustavh97 commented 1 year ago

@colemaring did that fix the issue?

colemaring commented 1 year ago

No it did not

Ghustavh97 commented 1 year ago

@colemaring please provide me with your stack or reproduction steps so I can try to fix the issue on my end.

colemaring commented 1 year ago
  1. npm create vite@latest -> choose Janilla Javascript.
  2. navigate to dir and run npm install, followed by npm install oslllo-svg-fixer.
  3. add "import SVGFixer from 'oslllo-svg-fixer'" to the main.js file.
  4. observe the ts error.

Using VS Code with the following extensions: https://gyazo.com/01f86b626f4608edc624331142fd3217

I appreciate your help greatly

Ghustavh97 commented 1 year ago

Ohhhh Vite!, I dont know how I missed that in your previous comment but you cannot run this package in vite because its a frontend environment aka browser.

This module requires a Node.js runtime because It depends on packages such as https://www.npmjs.com/package/domino which are server side only.

If you are trying to make a tool like https://iconly.io/tools/svg-convert-stroke-to-fill then you are going to need a node.js backend to do the processing, then send the results to the vite frontend.

colemaring commented 1 year ago

Got it, Ill need to use the node.js backend for what I am trying to do. Thank you.