npm run npm bin from within the same package - node.js

I'm working on extending open source raml2html library, which consumes raml contract to generate html docs. Key facts:
the library has a binary placed in bin/raml2html file; th ebinary is stated in package.json as follows:
"bin": {
"raml2html": "./bin/raml2html"
}
when npm install'ed by the users, the program is executed
I use the binary to update examples: both source .raml files and output .html files are kept in the repo. I'm using the binary with ./bin/raml2html examples/example.raml -o examples/example.html with git bash under windows and it works fine.
however, I want to wrap this commands as npm run script, so I define:
"scripts": {
...
"examples:example": "./bin/raml2html examples/example.raml -o examples/example.html",
"examples:github": "./bin/raml2html examples/github.raml -o examples/github.html",
"examples": "npm run examples:example && examples:github"
},
and when I call either npm run examples or npm run examples:example, both fail the same way:
`
$ npm run examples:example
> raml2html#2.4.0 examples:example C:\Users\tomasz.ducin\Development\GitHub\raml2html
> ./bin/raml2html examples/example.raml -o examples/example.html
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "examples:example"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! raml2html#2.4.0 examples:example: `./bin/raml2html examples/example.raml -o examples/example.html`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the raml2html#2.4.0 examples:example script './bin/raml2html examples/example.raml -o examples/example.html'.
npm ERR! This is most likely a problem with the raml2html package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./bin/raml2html examples/example.raml -o examples/example.html
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs raml2html
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls raml2html
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\tomasz.ducin\Development\GitHub\raml2html\npm-debug.log
It says that '.' is not recognized as an internal or external command - well, that's true, ./bin/raml2html is not how I should do that on windows. But it's being ran under node.js/npm layer and package.json:bin can understand this syntax. I get confused with that.
The question is: how can I set up npm run scrpt to use the binary inside the same package?

Related

NPM run dev command always fails at "grunt develop:quick" script

Using a cloned repository, I am trying to run npm run dev in order to develop locally. I have installed the grunt commands globally and my npm is recently updated. A possible problem I can see is that my node.js is at 5.10. However, if possible, I'd like to keep it there due to other team members having history with the repository not working on updated versions of node.js. The root of my repository is saved in the web folder and this is through Windows PowerShell(Admin).
PS C:\Users\<User>\Documents\GitHub\web> npm run dev
> web#12.5.6 dev C:\Users\<User>\Documents\GitHub\web
> grunt develop:quick
Running "develop:quick" (develop) task
Running "clean:server" (clean) task
>> 0 paths cleaned.
Running "copy:modules" (copy) task
Copied 24 files
Running "base-sass-config" task
Interim sass config file [client\styles\core\__config.scss] created.
Running "glob-sass-components" task
Traversing:
C:\Users\oalyousf\Documents\GitHub\web\client\src\components\pages
Traversing:
C:\Users\oalyousf\Documents\GitHub\web\client\src\components\building-blocks
Interim components glob file [client\styles\core\__components.scss] created.
Running "sass:static" (sass) task
>> File to import not found or unreadable: ....srcomponentspages­min-
consolestyles­min-console.scss
>> Parent style sheet:
C:/Users/<User>/Documents/GitHub/web/client/styles/core/__components.scss
>> Line 4 Column 1 client\styles\core\__components.scss
Warning: Use --force to continue.
Aborted due to warnings.
npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program
Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
npm ERR! node v5.10.1
npm ERR! npm v3.8.3
npm ERR! code ELIFECYCLE
npm ERR! web#12.5.6 dev: `grunt develop:quick`
npm ERR! Exit status 6
npm ERR!
npm ERR! Failed at the web#12.5.6 dev script 'grunt develop:quick'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the web package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! grunt develop:quick
npm ERR! You can get information on how to open an issue for this project
with:
npm ERR! npm bugs web
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls web
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\<User>\Documents\GitHub\web\npm-debug.log
PS C:\Users\<User>\Documents\GitHub\web>

Babel build program is breaking permission of NPM bin script

I have NPM package with a bin property linking to a script, e.g.
/foo/package.json
{
"name": "foo",
"bin": "./dist/index.js"
}
/foo/src/index.js
#! /usr/bin/env node
console.log('Hello, World!');
I use npm link to create a globally-installed symbolic link of foo package.
Then I use:
node ./node_modules/.bin/babel\
--watch ./src\
--out-dir ./dist
Next, I have a bar package.
package.json
{
"name": "bar",
"scripts": {
"test-foo": "foo"
}
}
I use npm link foo to create a symlink from the local node_modules folder to the global symlink.
Then I attempt to execute npm run test-foo. I expect to get "Hello, World!" message. Instead, I get the following error message:
npm run test-foo
> bar#0.0.0 test-foo /bar
> foo
sh: /Users/gajus/bar/node_modules/.bin/foo: Permission denied
npm ERR! Darwin 15.2.0
npm ERR! argv "/Users/gajus/.nvm/versions/node/v5.3.0/bin/node" "/Users/gajus/.nvm/versions/node/v5.3.0/bin/npm" "run" "test-foo"
npm ERR! node v5.3.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! bar#3.7.3 test-foo: `foo`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the table#3.7.3 test-foo script 'foo'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the table package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! foo
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs table
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls table
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/gajus/Documents/dev/gajus/table/npm-debug.log
Which is basically complaining that current user does not have permission to execute /Users/gajus/bar/node_modules/.bin/foo file.
I can solve this with:
chmod +x /Users/gajus/bar/node_modules/.bin/foo
However, I do not understand what is the reason that this file does not have permission to be executed in the first place. I am running babel program as the same user.
It appears to be an issue with the way NPM setups a global symlink (it sets it once. When babel --watch creates a new file, it no longer persists).
What is the solution to have +x persist with npm link?
The solution was pretty simple: give permissions to execute the source file, i.e.,
chmod +x /foo/src/index.js
When Babel program copies the files, it will also copy the permissions of that file. This works with --watch too.

To build AppRTC server

there.
I have trouble to build https://github.com/webrtc/samples in win 8.1.
I am trying to install npm dependencies.
But there are some errors like as the following.
node.js version is v4.2.3 and npm version is v2.14.7
D:\_Temp\AppRTC\samples>npm install
> travis-multirunner#3.0.0 postinstall D:\_Temp\AppRTC\samples\node_modules\trav
is-multirunner
> ./bin/travis-sync
'.' is not recognized as an internal or external command,
operable program or batch file.
> chromedriver#2.20.0 install D:\_Temp\AppRTC\samples\node_modules\chromedriver
> node install.js
Downloading http://chromedriver.storage.googleapis.com/2.20/chromedriver_win32.z
ip
Saving to C:\Users\JIS\AppData\Local\Temp\chromedriver\chromedriver_win32.zip
Receiving...
Received 782K...
Received 1564K...
Received 2346K...
Received 2398K total.
Extracting zip contents
Copying to target path D:\_Temp\AppRTC\samples\node_modules\chromedriver\lib\chr
omedriver
Done. ChromeDriver binary available at D:\_Temp\AppRTC\samples\node_modules\chro
medriver\lib\chromedriver\chromedriver.exe
> utf-8-validate#1.2.1 install D:\_Temp\AppRTC\samples\node_modules\selenium-web
driver\node_modules\ws\node_modules\utf-8-validate
> node-gyp rebuild
D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver\node_modules\ws\node_mod
ules\utf-8-validate>if not defined npm_config_node_gyp (node "C:\Program Files\n
odejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gy
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
validation.cc
win_delay_load_hook.c
Creating library D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver\n
ode_modules\ws\node_modules\utf-8-validate\build\Release\validation.lib and o
bject D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver\node_modules\ws
\node_modules\utf-8-validate\build\Release\validation.exp
Generating code
Finished generating code
validation.vcxproj -> D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver
\node_modules\ws\node_modules\utf-8-validate\build\Release\\validation.node
> bufferutil#1.2.1 install D:\_Temp\AppRTC\samples\node_modules\selenium-webdriv
er\node_modules\ws\node_modules\bufferutil
> node-gyp rebuild
D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver\node_modules\ws\node_mod
ules\bufferutil>if not defined npm_config_node_gyp (node "C:\Program Files\nodej
s\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js
" rebuild ) else (node rebuild )
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
bufferutil.cc
win_delay_load_hook.c
Creating library D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver\n
ode_modules\ws\node_modules\bufferutil\build\Release\bufferutil.lib and objec
t D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver\node_modules\ws\nod
e_modules\bufferutil\build\Release\bufferutil.exp
Generating code
Finished generating code
bufferutil.vcxproj -> D:\_Temp\AppRTC\samples\node_modules\selenium-webdriver
\node_modules\ws\node_modules\bufferutil\build\Release\\bufferutil.node
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.2.3
npm ERR! npm v2.14.7
npm ERR! code ELIFECYCLE
npm ERR! travis-multirunner#3.0.0 postinstall: `./bin/travis-sync`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the travis-multirunner#3.0.0 postinstall script './bin/travis
-sync'.
npm ERR! This is most likely a problem with the travis-multirunner package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./bin/travis-sync
npm ERR! You can get their info via:
npm ERR! npm owner ls travis-multirunner
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! D:\_Temp\AppRTC\samples\npm-debug.log
D:\_Temp\AppRTC\samples>node test/server.js
D:\_Temp\AppRTC\samples\test\server.js:18
key: keys.serviceKey,
^
TypeError: Cannot read property 'serviceKey' of undefined
at D:\_Temp\AppRTC\samples\test\server.js:18:14
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:246:24
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:150:24
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:71:20
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:951:20
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:930:13
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:829:20
at D:\_Temp\AppRTC\samples\node_modules\pem\lib\pem.js:999:20
at F (D:\_Temp\AppRTC\samples\node_modules\pem\node_modules\which\which.js:7
3:25)
at E (D:\_Temp\AppRTC\samples\node_modules\pem\node_modules\which\which.js:7
6:29)
Thanks for any reply.
It's quite easy to setup a virtual machine using Virtualbox.
In fact I did just that at home on my gaming pc, just installed latest Debian, node.js, Sublime in a Virtualbox VM, then I use Virtualbox seamless mode which just puts the Windows in the VM on top of the host OS desktop.
Works great!
travis-multirunner which is used for automatted testing is not supported on windows.

npm run cmd fails while cmd on command line works

In my HTTP Status Check project:
If I run node_modules/.bin/jshint . I get:
$ node_modules/.bin/jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.
1 error
It executes correctly and produces the expected output: 1 error.
But if I add that command to package.json and try and run it through npm run then it works and produces the expected output but also follows that with a bunch of errors:
$ npm run jshint
> http-status-check#0.0.5 jshint /home/guy/source/http-status-check
> jshint .
test/inAdapters_fileAdapter.js: line 73, col 31, Missing semicolon.
1 error
npm ERR! Linux 3.13.0-24-generic
npm ERR! argv "node" "/home/guy/local/bin/npm" "run" "jshint"
npm ERR! node v0.10.31
npm ERR! npm v2.0.0
npm ERR! code ELIFECYCLE
npm ERR! http-status-check#0.0.5 jshint: `jshint .`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the http-status-check#0.0.5 jshint script.
npm ERR! This is most likely a problem with the http-status-check package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! jshint .
npm ERR! You can get their info via:
npm ERR! npm owner ls http-status-check
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/guy/source/http-status-check/npm-debug.log
This is how it's defined in package.json:
"scripts": {
"jshint": "node_modules/.bin/jshint .",
},
What have I done wrong?
Don't exit with a non-zero error code unless you really mean it. Except for uninstall scripts, this will cause the npm action to fail, and potentially be rolled back. If the failure is minor or only will prevent some optional features, then it's better to just print a warning and exit successfully.
From https://www.npmjs.org/doc/misc/npm-scripts.html
Use:
node_modules/.bin/jshint .; true
Or write a wrapper that calls jshint and then ignores the exit code and exits successfully with a exit code of zero.

npm error ELIFECYCLE while running the test

I am using mocha-phantomjs setup for unit testing. I have following package.json scriot to run the tests.
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html"
}
This run ok in browser. And when I run the command npm testin cmd, the test run alright but it also gives following error
3 passing (5s)
6 failing
npm ERR! flickr-test# testFlickr: `mocha-phantomjs ./test/FlickrTest.html`
npm ERR! Exit status 6
npm ERR!
npm ERR! Failed at the flickr-test# testFlickr script.
npm ERR! This is most likely a problem with the flickr-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha-phantomjs ./test/FlickrTest.html
npm ERR! You can get their info via:
npm ERR! npm owner ls flickr-test
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7600
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "testFlickr"
npm ERR! cwd C:\Users\user\Desktop\test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\Users\user\Desktop\test\npm-debug.log
npm ERR! not ok code 0
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
Please can anyone tell me how can I resolve this error.
I was having this same problem, and what fixed it for me was when I run my unit tests, do NOT use
npm run test
instead use:
npm test
When running npm test it squelches ELIFECYCLE errors so you never encounter this experience.
Reference to code
Once you move a test script to a different script-name you'll start seeing ELIFECYCLE errors.
My fix is to add a exit 0 to the end of the command. For your code it would look like this:
"scripts": {
"test": "npm run testFlickr",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html; exit 0"
}
And when I run the command npm test in cmd, the test run alright
No they aren't. You have 6 failing tests. The exit code of mocha-phantomjs is equal to the number of failing tests. Run mocha-phantomjs ./test/FlickrTest.html directly and see what is failing. Realize the PhantomJS is a bit different than your browser - you may have to debug it.
Your script setup is odd. You should just have:
"scripts": {
"test": "mocha-phantomjs ./test/FlickrTest.html"
}
Then the odd node errors should go away.
This is a problem when using npm run, it has to do with Mocha exiting with code !== 0 whenever a test fails. If you are on Windows try this:
"scripts": {
"test": "npm run testFlickr || ECHO.",
"testFlickr": "mocha-phantomjs ./test/FlickrTest.html || ECHO."
}

Resources