Search code examples
npmsassyarnpkgnode-sassnpm-scripts

npm script succeeds when I run a named task, but not when I run the cli commands it describes (node-sass)


I have a build config for npm that runs a bunch of the commands, but it is failing. This is the npm script that seems to be the problem:

"build-css": "node-sass src/styles/main.scss dist/static/css/main.css --output-style compressed",

If I run yarn run build-css, it will successfully compile the css.

But if I run the command inside of it explicitly:

node-sass src/styles/main.scss dist/static/css/main.css --output-style compressed

It says:

no such file or directory: node-sass

This worked at one point and no longer does, and I'm not sure what changed.


Solution

  • node-sass was probably installed globally and now it's not - hence why it worked at one point when running the command explicitly.

    A local copy of node-sass can be run by invoking the version which resides in the projects node_modules/.bin directory instead.

    1. Firstly cd to your projects directory.
    2. Run node_modules/.bin/node-sass src/styles/main.scss dist/static/css/main.css --output-style compressed

    Note your original command has been prefixed with: node_modules/.bin/