When I run npm run generate
npm script, got error:
> @svgr/cli --out-dir ./src/components --typescript -- ./src/assets
/cli does not exist
npm error Lifecycle script `generate` failed with error:
npm error Error: command failed
But build
, lint
npm script can be executed correctly. I remember if the CLI packages are installed locally, we don't need to use npx
like npx tsc
.
As you can see, I have already installed the @svgr/cli
package.
"scripts": {
"build": "tsc -b && vite build",
"lint": "eslint .",
"generate": "@svgr/cli --out-dir ./src/components --typescript -- ./src/assets",
},
"devDependencies": {
"vite-plugin-dts": "^4.3.0",
"@eslint/js": "^9.15.0",
"@svgr/cli": "^8.1.0",
"@types/node": "^22.10.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.15.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.12.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.15.0",
"vite": "^6.0.1"
},
Run:
npm install @svgr/cli --save-dev
Add to config:
"scripts": {
"generate": "svgr --out-dir ../src/components --typescript ./src/assets"
}