npm run script 导致 Windows Script Host 错误 [英] npm run script causes Windows Script Host error

查看:87
本文介绍了npm run script 导致 Windows Script Host 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 npm 来缩小 javascript.

I a trying to use npm to minify javascript.

这是我的 package.json:

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"
  }
}

我的 minifyJs 脚本是:

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);

当我调用 npm run minifyjs 时,出现以下错误:

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

我做错了什么 - 顺便说一句,这是在另一台机器上工作......

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

有人可以帮忙吗?

推荐答案

scripts 下的条目是由 NPM 运行的命令.它们不仅仅是 JavaScript 文件的路径.

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

您需要告诉 NPM 使用 node 运行您的 JavaScript 任务:

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

...
"scripts": {
  "minifyjs": "node minifyJs",
  "minifycss": "node minifyCss",
  "minifyhtml": "node minifyHtml"
},
...

这篇关于npm run script 导致 Windows Script Host 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆