Skip to content

Doesn't work with Windows #5

Closed
Closed

Description

@cpu999

I tried to use this in Windows but it fails. I traced the issue to the use of single quotes. Windows doesn't recognize 'just one parm' as a single parameter, but as 3 parameters which with bash/unix would have been typed 'just one parm'. In the example of running "npm run watch" I got an error telling me that 'npm isn't an executable (notice the leading quote). I added some logging and I got this:

C:\usr\local\angular\projects\npm-scripts-example-master>parallelshell 'where npm'
[ 'node',
  'C:\\usr\\local\\angular\\projects\\npm-scripts-example-master\\node_modules\\parallelshell\\index.js',
  '\'where',
  'npm\'' ]

C:\usr\local\angular\projects\npm-scripts-example-master>parallelshell "where npm"
[ 'node',
  'C:\\usr\\local\\angular\\projects\\npm-scripts-example-master\\node_modules\\parallelshell\\index.js',
  'where npm' ]

As you can see, single quotes and double quotes aren't considered the same in windoze. :-( (You can thank Billy for that.)

So, I was able to get a bit further along by doing something like this:

"watch": "parallelshell \"npm run watch:test -s\" \"npm run watch:build -s\"",

I also noticed that this was frowned upon by npm:

"watch": 'parallelshell "npm run watch:test -s" "npm run watch:build -s"',

It wants the "watch" parameter to start with a double quote and gives this error:
npm ERR! Failed to parse json
npm ERR! Unexpected token '

I also tried with Cygwin and bash provided in Git, without success, and this problem is not just limited to 'parallelshell' but even this fails:

"build": "npm run build:scripts -s && npm run build:styles -s && npm run build:markup -s",

So, in the end even if this seems like a good idea, it didn't work but it would be nice if it did.

Activity

  1. christianseel commented on Jan 15, 2015

    @christianseel

    Hey, from my latest experience it works just fine if you replace all ' (single quote) with \" (escaped double quote)…

  2. cpu999 commented on Jan 15, 2015

    @cpu999
    Author

    Christian,

    I hope this will help as I am not trying to complain.

    I installed your example from the downloaded ZIP. Then I ran "npm
    install" to get all the dependencies. The "npm run watch" still fails
    but some commands work, like the "npm run build". I tried this on 2
    machines as the corporate computer is sometimes tempermental but my
    personal computer isn't. I got the same results.

    Here is some of the run samples: (I highlighted the command lines but
    the email program highlighted what looks like email addresses)

    C:\usr\local\angular\projects\npm-scripts-example-master>npm run watch

    [email protected] watch
    C:\usr\local\angular\projects\npm-scripts-example-master
    parallelshell "npm run watch:test -s" "npm run watch:build -s"

    npm run watch:build -s failed with exit code 1

    npm ERR! [email protected] watch: parallelshell "npm run watch:test -s" "npm run watch:build -s"
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] watch script.
    npm ERR! This is most likely a problem with the npm-scripts-example
    package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR! parallelshell "npm run watch:test -s" "npm run watch:build
    -s"
    npm ERR! You can get their info via:
    npm ERR! npm owner ls npm-scripts-example
    npm ERR! There is likely additional logging output above.
    npm ERR! System Windows_NT 6.1.7601
    npm ERR! command "C:\usr\local\nodejs\node.exe"
    "C:\usr\local\nodejs\node_modules\npm\bin\npm-cli.js" "run"
    "watch"
    npm ERR! cwd C:\usr\local\angular\projects\npm-scripts-example-master
    npm ERR! node -v v0.10.33
    npm ERR! npm -v 1.4.28
    npm ERR! code ELIFECYCLE
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR!
    C:\usr\local\angular\projects\npm-scripts-example-master\npm-debug.log
    npm ERR! not ok code 0

    C:\usr\local\angular\projects\npm-scripts-example-master>npm run
    watch:build

    [email protected] watch:build
    C:\usr\local\angular\projects\npm-scripts-example-master
    nodemon -q -w assets/ --ext "." --exec "npm run build"

    npm ERR! [email protected] watch:build: nodemon -q -w assets/ --ext "." --exec "npm run build"
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] watch:build script.
    npm ERR! This is most likely a problem with the npm-scripts-example
    package,
    npm ERR! not with npm itself.
    npm ERR! Tell the author that this fails on your system:
    npm ERR! nodemon -q -w assets/ --ext "." --exec "npm run build"
    npm ERR! You can get their info via:
    npm ERR! npm owner ls npm-scripts-example
    npm ERR! There is likely additional logging output above.
    npm ERR! System Windows_NT 6.1.7601
    npm ERR! command "C:\usr\local\nodejs\node.exe"
    "C:\usr\local\nodejs\node_modules\npm\bin\npm-cli.js" "run"
    "watch:build"
    npm ERR! cwd C:\usr\local\angular\projects\npm-scripts-example-master
    npm ERR! node -v v0.10.33
    npm ERR! npm -v 1.4.28
    npm ERR! code ELIFECYCLE
    npm ERR!
    npm ERR! Additional logging details can be found in:
    npm ERR!
    C:\usr\local\angular\projects\npm-scripts-example-master\npm-debug.log
    npm ERR! not ok code 0

    C:\usr\local\angular\projects\npm-scripts-example-master>npm run build

    [email protected] prebuild
    C:\usr\local\angular\projects\npm-scripts-example-master
    npm run clean -s

    [email protected] build
    C:\usr\local\angular\projects\npm-scripts-example-master
    npm run build:scripts -s && npm run build:styles -s && npm run
    build:markup -s

    generated dist\main.css.map
    compiled dist\main.css

    rendered dist\index.html

    C:\usr\local\angular\projects\npm-scripts-example-master>
    Although I would very much like to be able to use npm to configure the
    builds, it seems that there still is some reason why other build tools
    were developed.

    Thanks.

    Gerard Perreault

    ------ Original Message ------
    From: "Christian Seel" [email protected]
    To: "keithamus/npm-scripts-example"
    [email protected]
    Cc: "cpu999" [email protected]
    Sent: 1/15/2015 1:23:40 PM
    Subject: Re: [npm-scripts-example] Doesn't work with Windows (#5)

    Hey, from my latest experience it works just fine if you replace all '
    (single quote) with " (escaped double quote)…

    —
    Reply to this email directly or view it on GitHub.

  3. keithamus commented on Jan 15, 2015

    @keithamus
    Owner

    @cpu999 try downloading the example again, it should work now.

  4. keithamus commented on Jan 15, 2015

    @keithamus
    Owner

    Thanks @christianseel for suggesting the fix 😄

  5. cpu999 commented on Jan 15, 2015

    @cpu999
    Author

    Actually, it still didn't work. I replaced all the single quotes by " and now the "npm run build" works. However, the "watch:build" still fails. I suspect it may have to do with the use of "nodemon", the "--exec" parameter. If I recall correctly, "exec" requires an executable and "npm" is not one, it is a script.

    This is what I had to change it to:

    {
      "name": "npm-scripts-example",
      "version": "1.0.0",
      "description": "An example of how to use npm scripts over a build tool like Grunt or Gulp",
      "main": "index.js",
      "author": "Keith Cirkel <[email protected]> (http://keithcirkel.co.uk/)",
      "license": "MIT",
      "devDependencies": {
        "browserify": "^6.3.2",
        "hashmark": "^2.0.0",
        "http-server": "^0.7.3",
        "jade": "^1.7.0",
        "jshint": "^2.5.10",
        "karma": "^0.12.28",
        "karma-browserify": "^1.0.0",
        "karma-cli": "^0.0.4",
        "karma-mocha": "^0.1.10",
        "karma-phantomjs-launcher": "^0.1.4",
        "live-reload": "^0.2.0",
        "minifyify": "^4.4.0",
        "mocha": "^2.0.1",
        "nodemon": "^1.2.1",
        "opener": "^1.4.0",
        "parallelshell": "^1.0.0",
        "rimraf": "^2.2.8",
        "s3-cli": "^0.11.1",
        "stylus": "^0.49.3"
      },
      "scripts": {
        "clean": "rimraf dist/*",
    
        "prebuild": "npm run clean -s",
        "build": "npm run build:scripts -s && npm run build:styles -s && npm run build:markup -s",
        "build:scripts": "browserify -d assets/scripts/main.js -p [minifyify --compressPath . --map main.js.map --output dist/main.js.map] | hashmark -n dist/main.js -s -l 8 -m assets.json \"dist/{name}{hash}{ext}\"",
        "build:styles": "stylus assets/styles/main.styl -m -o dist/ && hashmark -s -l 8 -m assets.json dist/main.css \"dist/{name}{hash}{ext}\"",
        "build:markup": "jade assets/markup/index.jade --obj assets.json -o dist",
    
        "test": "karma start --singleRun",
    
        "watch": "parallelshell \"npm run watch:test -s\" \"npm run watch:build -s\"",
        "watch:test": "karma start",
        "watch:build": "nodemon -q -w assets/ --ext \".\" --exec \"cmd /c npm run build\"",
    
        "open:prod": "opener http://example.com",
        "open:stage": "opener http://staging.example.internal",
        "open:dev": "opener http://localhost:9090",
    
        "deploy:prod": "s3-cli sync ./dist/ s3://example-com/prod-site/",
        "deploy:stage": "s3-cli sync ./dist/ s3://example-com/stage-site/",
    
        "serve": "http-server -p 9090 dist/",
        "live-reload": "live-reload --port 9091 dist/",
    
        "dev": "npm run open:dev -s & parallelshell \"npm run live-reload -s\" \"npm run serve -s\" \"npm run watch -s\""
      }
    }
    

    Notice that on the --exec I added "cmd /c" and now it works. However, that makes the build not compatible in both Unix and Windows. I'll let you know if I figure out something.

  6. christianseel commented on Jan 16, 2015

    @christianseel

    We had the same issue with nodemon under windows. It seems like you can't execute npn run from nodemon. Thats why we replaced it with watch:
    like "watch:build": "watch \"npm run build\" assets/sources"

  7. keithamus commented on Jan 16, 2015

    @keithamus
    Owner

    Nodemon has an issue here: remy/nodemon#389. Anyone experiencing this issue with nodemon should file it there - it looks like it may be coming toward a fix, but I'm sure your experiences would help.

  8. amg-design commented on Dec 4, 2017

    @amg-design

    thanks guys! I had the same issue and now it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions