Search code examples
javascriptnode.jsnpmchokidar

Chokidar runs on console but doesn't work when called via 'npm run'


i've added a script to watch over Tailwind CSS files with Chokidar. Now its working when i call the command in the cli using chokidar 'tailwind.config.js' --initial=true -c 'npm run build-tailwind'. It works perfectly and runs the corresponding command on change, but when i use it in my package json like so

"watch-tailwind": "chokidar 'tailwind.config.js' --initial=true -c 'npm run build-tailwind'",

and call it via npm run watch-tailwind.

$ npm run watch-tailwind

> [email protected] watch-tailwind C:\xampp\htdocs\bloodline
> chokidar 'tailwind.config.js' --initial=true -c 'npm run build-tailwind'

Watching "'tailwind.config.js'", "run", "build-tailwind'" ..

And when i modify the tailwind.config.js file it remains the same and it wont trigger the update. The text remains the same in cli. When in reality it should have added some extra lines like so

change:tailwind.config.js

> [email protected] build-tailwind C:\xampp\htdocs\bloodline
> postcss src/renderer/assets/scss/tailwind/tailwind.scss -o src/renderer/assets/scss/tailwind/_build.scss

But the files dont change nor it does anything. What am i doing wrong?


Solution

  • I don't know why but there's a weird issue with single quotations in windows 10, so i changed

    "watch-tailwind": "chokidar 'tailwind.config.js' --initial=true -c 'npm run build-tailwind'",
    

    to

    "watch-tailwind": "chokidar \"tailwind.config.js\" --initial=true -c \"npm run build-tailwind\"",
    

    and it fixed the problem.