Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm run script causes Windows Script Host error

Tags:

npm

I a trying to use npm to minify javascript.

This is my package.json:

{
  "name": "name1",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "minifyjs": "minifyJs",
    "minifycss": "minifyCss",
    "minifyhtml": "minifyHtml"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "clean-css": "^3.4.19",
    "html-minifier": "^3.0.2",
    "uglify-js": "^2.7.0"
  }
}

and my minifyJs script is :

var uglifyJS = require('uglify-js');
var fs = require('fs');

var result = uglifyJS.minify(['src/main1.js', 'src/main2.js'], {
    compress: {
        drop_console: true,
        unused: true
    }
});
fs.writeFileSync('dist/minifyJs.js', result.code);

When I call npm run minifyjs I get the following error:

enter image description here

What am I doing wrong - btw this was working on another machine.....

Can anyone help?

like image 507
Ilyas Avatar asked Aug 13 '16 20:08

Ilyas


People also ask

How do I fix npm run start error?

To solve the npm ERR! Missing script: "start" error, make sure to add a start command to the scripts object in your package. json file and open your shell or IDE in the root directory of your project before running the npm start command.

How do I disable Microsoft Windows Script Host?

Enable, Disable Windows Script Host To activate or deactivate the Windows Script Host, type regedit.exe in the Run box and press Enter to open the Registry Editor. In the right panel, you will see Enable. If you see 0 entries, it means that Windows Script Host access is disabled on your Windows.


1 Answers

The entries under scripts are commands that are run by NPM. They are not simply paths to JavaScript files.

You need to tell NPM to run your JavaScript tasks using node:

...
"scripts": {
  "minifyjs": "node minifyJs",
  "minifycss": "node minifyCss",
  "minifyhtml": "node minifyHtml"
},
...
like image 176
cartant Avatar answered Sep 28 '22 16:09

cartant