2

Using node and npm and as a task runner from gitbash cli. I have set up and tested, all works well for the most part. The problem I am having is I cannot seem to call tasks in separate .js files from my package.json. Could I have some assistance with the syntax please.

concat-css.js is in the same folder as package.json.

My task:

var concat = require('concatenate-files');

concat('deploy/css/min/*.css', 'deploy/css/css.css', { separator: ';' }, function(err, result) {
 // result == { outputFile: 'out.js', outputData: '...' }
});

The script from package.json:

"scripts": {"concat-css": "npm run concat"}

The dependency concatenate-files is installed and a local and global dependency:

"devDependencies": {"concatenate-files": "^0.1.1"}

"dependencies": {"concatenate-files": "^0.1.1"}

But I get this error when I run the task:

npm run concat-css


npm ERR! missing script: concat

I honestly can't work out whats wrong and have hit a dead end. The resources online for npm are a bit patchy. Can anyone point me in the right direction. The duplicate question flagged is too general and would not have helped me.

JPB
  • 592
  • 2
  • 6
  • 28
  • 3
    `npm run concat` tries to run a script with name `concat`. All you have defined in your `package.json` file is a script with name `concat-css`. `concat` doesn't exist, hence the error `missing script: concat`. So it seems you don't actually want to run `npm run concat`. Maybe you want to run your JavaScript file instead, which would be `"scripts": {"concat-css": "node concat-css.js"}`? – Felix Kling Jan 05 '17 at 02:01
  • Thanks mate will try now. – JPB Jan 05 '17 at 02:04
  • Possible duplicate of [How do you run a js file using npm scripts?](http://stackoverflow.com/questions/32964900/how-do-you-run-a-js-file-using-npm-scripts) – cartant Jan 05 '17 at 02:10
  • That was it. Thanks, so simple yet somehow i couldnt see it! – JPB Jan 05 '17 at 02:12
  • @cartant that question would not have helped me, this is very specific. Thanks for the help though, felix got in first but ill mark you correct if he doesn't post the answer. – JPB Jan 05 '17 at 02:15
  • @felix how do I mark you correct? – JPB Jan 05 '17 at 02:25
  • 1
    Just accept cartant's answer :) – Felix Kling Jan 05 '17 at 02:38

1 Answers1

5

If you want to run a simple, JavaScript task, you need to indicate to NPM that it's to be run using Node:

{
    ...
    "scripts": {
        "concat-css": "node concat-css.js"
    }
}
cartant
  • 57,105
  • 17
  • 163
  • 197