NPM - npm手表不工作

时间:2016-06-09 09:52:29

标签: npm

我正在创建一个简单的npm手表来观看并生成一个sass文件。

我有这段代码

    {
      "name": "npm-test",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
         "scss": "node-sass --output-style compressed -o css/output css/*scss",
         "watch": "watch 'npm run scss' css/*.scss"

      },
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "node-sass": "^3.7.0",
        "watch": "^0.18.0"
      }
    }

我收到此错误

    > npm-test@1.0.0 watch /Users/ch-d/Desktop/npm-test
    > watch 'npm run scss' css/*.scss

    > Watching css/main.scss
    /Users/ch-d/Desktop/npm-test/node_modules/watch/main.js:73
        if (err) throw err;
                       ^
    Error: ENOTDIR, scandir 'css/main.scss'
        at Error (native)

    npm ERR! Darwin 15.4.0
    npm ERR! argv "node" "/usr/local/bin/npm" "run" "watch"
    npm ERR! node v0.12.4
    npm ERR! npm  v2.10.1
    npm ERR! code ELIFECYCLE
    npm ERR! npm-test@1.0.0 watch: `watch 'npm run scss' css/*.scss`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the npm-test@1.0.0 watch script 'watch 'npm run scss' css/*.scss'.
    npm ERR! This is most likely a problem with the npm-test package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR!     watch 'npm run scss' css/*.scss
    npm ERR! You can get their info via:
    npm ERR!     npm owner ls npm-test
    npm ERR! There is likely additional logging output above.

    npm ERR! Please include the following file with any support request:
    npm ERR!     /Users/ch-d/Desktop/npm-test/npm-debug.log     

我可以运行'npm run scss'而且可以运行但不是手表

2 个答案:

答案 0 :(得分:2)

假设您正在使用watch,它只在命令行中使用目录参数,而不是文件通配符。我刚刚在自己的系统上证实了这一点......

您可以通过编程方式使用watch来执行更多有趣或复杂的操作......但CLI非常基本。

您可以将行更改为watch 'npm run scss' css/,或者您可以查看更具编程性的内容,例如监视脚本或更复杂的内容,例如基于grunt或gulp的方法。

答案 1 :(得分:0)

还请注意在 Windows操作系统下。使用Windows,我遇到了使用简单引号的问题。以下对我不起作用:

"watch:css": "watch 'npm run scss' ./scss --interval=1"

下一个是正确的:

"watch:css": "watch \"npm run scss\" ./scss --interval=1"

注意转义的报价