1

I am developing a NPM that has a command(script) that I want to use, but I cannot use it unless I add the scripts to the project's package.json file. I want to avoid this method and use a command to run the script (I don't mind adding more packages).

custom-npm package.json


"scripts":{
   "custom-script": "node-sass --watch scss -o dist/css"
}

How can I run that script with a command (like: npm run custom-script)? Do I need to have global dependencies to run the script?

edit: I tried using npx but I would get these messages:

user@username project % npx custom-script
npx: installed 1 in 1.204s
Unexpected token import
user@username project % npx custom-npm custom-script
npx: installed 1 in 1.196s
Unexpected token import

Not sure what the Unexpected token import is all about

Scotty
  • 29
  • 6
  • Maybe [https://stackoverflow.com/questions/50605219/difference-between-npx-and-npm](https://stackoverflow.com/questions/50605219/difference-between-npx-and-npm) helps. – pzaenger Dec 17 '19 at 21:56
  • @pzaenger I tried using `npx` but all it does is download something. Here are the messages: `npx: installed 1 in 1.196s` and `Unexpected token import`. Not sure what token it could be talking about. – Scotty Dec 17 '19 at 22:05
  • Via your command line if you `cd` to your project directory then run `./node_modules/.bin/node-sass --watch scss -o dist/css` that should to be the same as running `npm run custom-script` . I'm assuming that `node-sass` has been installed locally within the projects node_modules directory for the aforementioned command to run successfully. Otherwise install `node-sass` globally to get the `node-sass` command. – RobC Dec 20 '19 at 13:37

0 Answers0