Error importing
Closed this issue · 8 comments
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..
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')
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.
@colemaring did that fix the issue?
No it did not
@colemaring please provide me with your stack or reproduction steps so I can try to fix the issue on my end.
- npm create vite@latest -> choose Janilla Javascript.
- navigate to dir and run npm install, followed by npm install oslllo-svg-fixer.
- add "import SVGFixer from 'oslllo-svg-fixer'" to the main.js file.
- observe the ts error.
Using VS Code with the following extensions: https://gyazo.com/01f86b626f4608edc624331142fd3217
I appreciate your help greatly
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.
Got it, Ill need to use the node.js backend for what I am trying to do. Thank you.