global cli npm package works on windows but not linux - javascript

I am wanting to create an npm cli tool, I dug around in bower's code and replicated their basic package.json along with the bin and lib/bin file.
On windows it works perfectly, but on linux I just get : No such file or directory
The npm package is: https://www.npmjs.com/package/quilk
Here is the code, package.json:
{
"name": "quilk",
"version": "0.1.3",
"description": "quilk.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "John Carmichael",
"keywords": [
"builder", "watcher", "fast", "quilk"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/johnc1984/quilk"
},
"main": "lib",
"bin": {
"quilk": "bin/quilk"
},
"files": [
"bin",
"lib"
],
"homepage": "https://github.com/johnc1984/quilk",
"engines": {
"node": ">=0.10.0"
},
"dependencies": {
"browserify" : "13.1.0",
"concat-files" : "0.1.0",
"chokidar" : "1.6.0",
"fs.extra" : "1.3.2",
"javascript-natural-sort" : "0.7.1",
"jdc-node-cliarg-reader" : "1.0.0",
"less" : "2.7.1",
"node-notifier" : "4.6.1",
"node-minify" : "1.3.9",
"q" : "1.4.1",
"recursive-readdir" : "2.0.0"
}
}
bin/quilk:
#!/usr/bin/env node
require('../lib/bin/quilk');
lib/bin/quilk
process.bin = process.title = 'quilk';
console.log('This is the quilk script.');
The end result of installing this globally on windows is the console.log is run on the output is This is the quilk script. after i simply type quilk.
On Ubuntu 14lts though, trying to run the freshly, globally installed npm module results in the output of : No such file or directory
What am I missing to get this run on linux?
(when i run the command to list the globally installed npm modules npm ls -g quilk is listed)
Further info:
I get the exact same issue on the following builds:
Ubuntu 14lts, node 6.4.0, npm 3.10.3
Debian 6.0.10, node 0.12.7, npm 2.11.3

I found the answer.
It turns out to be some kind of bug in npm on windows 10.
After publishing the same package from a linux box, the npm package now works on both linux and windows leading me to believe that npm publish on windows has some bug in it somewhere.
Issue reported: https://github.com/npm/npm/issues/13808

Related

Why won't my breakpoints get hit in Visual Studio Code

I'm trying the get the Visual Studio Code debugger working in my angular/typescript application but it's not working.
Here's what I have:
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug node",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"localRoot": "${workspaceFolder}\\.dist",
"remoteRoot": "/usr/src/api/.dist",
"type": "node"
}
]
}
scripts/local-entry-point.sh
#!/usr/bin/env sh
set -e
echo "STARTING local-entry-point.sh"
FOLDER=/tmp/.dist
if [ ! -d "$FOLDER" ]; then
mkdir /tmp/.dist
fi
false | cp -ir ${FOLDER} /usr/src/api/ 2>/dev/null
rm -rf ${FOLDER}
cd scripts
npm run watch
scripts/package.json
{
"private": true,
"devDependencies": {
"#effect-ts/core": "^0.11.1"
},
"scripts": {
"watch": "nodemon --watch '/usr/src/api/.dist/**/*' -e ts,json,js -x npm run debug",
"debug": "node --inspect=0.0.0.0:9229 /usr/src/api/.dist/start.js"
}
}
docker-compose.yml
...
ports:
- 4002:8800
- 9229:9229
...
I put breakpoints in both my Typescript and the compiled Javascript in the .dist folder (on the corresponding line):
I start my application (npm run docker), start the debugger in vscode, go through the steps to run the code, but the breakpoints don't get hit.
Seems like you are using Typescript. AFAIK VSCode debugger needs a sourcemap to put breakpoints on ts projects. I think this doc might help https://code.visualstudio.com/docs/typescript/typescript-debugging

Editing package.js file

i'm having a hard time to understand how to run all of my .js files using package.js files
i have almost 2000.js scripts i need to run them one by one, i'm using a api made by gameflip
in the folder i found package.js, but i don't know how to use it ,
can anyone tell me how to do that ? thank you
here the script :
{
"name": "gfapi",
"version": "0.1.1",
"description": "Gameflip API",
"keywords": "Gameflip",
"homepage": "https://github.com/iJJi/gfapi",
"bugs": "https://github.com/iJJi/gfapi/issues",
"author": {
"name": "Eng-Shien Wu",
"email": "engshien.wu#ijji.com"
},
"license": "MIT",
"private": true,
"files": [
"index.js"
],
"repository": "iJJi/gfapi",
"engines": {
"node": ">=8.5.0"
},
"scripts": {
"bulk_listing": "node src/samples/bulk_listing.js",
"test": "ENVIRONMENT=mocha mocha src/test --recursive",
"docs": "jsdoc -c jsdoc_conf.js -d docs -P package.json index.js; docco -o docs/samples src/samples/*.js src/samples/*.rb"
},
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^3.5.0",
"bunyan": "^1.8.12",
"file-type": "^8.1.0",
"http-errors": "^1.6.2",
"node-rest-client-promise": "^3.1.1",
"promise-ratelimit": "^0.0.3",
"request": "^2.85.0",
"request-promise": "^4.2.2",
"speakeasy": "^2.0.0"
},
"devDependencies": {
"marked": "^0.3.19",
"docco": "^0.7.0",``
"jsdoc": "^3.5.5"
}
}
What you posted isn't a package.js (I don't even know if it exists), but a package.json. It's generated by NPM, the Node Package Manager. It's a list of all the project's dependencies. I think that what you're looking for are the npm scripts, they are in the script object of package.json.
npm run <script>
# For example :
npm run bulk_listing
npm run test
npm run docs
Each script will run its associated command in this package.json.
npm run bulk_listing
# Will do the same thing as:
node src/samples/bulk_listing.js
More about package.json.
The script I talked about below
If you want to run all the scripts, this should do the job :
const fileNames = ["path/to/fileA", "fileB"]; // I assume you have something to get all the files path. Isn't that npm run bulk_listing ?
fileNames.forEach(async (path, index) => {
// It's pretty much like 'node <path>'
await require(path);
// All the code here is executed AFTER the script has been launched
console.log(`LAUNCHED ${index} | ${path}`)
});

Lite-server not working

I had a project that was previously using lite-server. I can no longer get it to run using
npm run
I see the following from the console
PS C:\Users\XXX\Documents\Work\Repos\Homepage_Slider> npm run
Lifecycle scripts included in homepage_slider: test
echo "Error: no test specified" && exit 1 start
lite-server
I don't really understand why this isn't working anymore.
I've tried:
Updating NPM
Running lite-server globably
Make sure package.json is set up correctly
Here is my package.json file
{
"name": "homepage_slider",
"version": "1.0.0",
"description": "A simple slider for homepage",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
"repository": {
"type": "git",
"url": "XXX"
},
"keywords": [
"Slider"
],
"author": "XXX",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.3.0"
},
"dependencies": {
"npm": "^6.0.1"
}
}
npm run is a reserved word for npm itself. Check the documentation
What you really need is npm start which is a shortcut for npm run start which is a shortcut for npm run-script start!

Globally-installed NodeJS npm module does not execute the main/bin JavaScript file with node

I've a package.json like this:
{
"name": "some-module",
"version": "1.0.0",
"bin": "./bin/some-module.js",
"main": "./bin/some-module.js",
"description": "Some module description",
"homepage": "http://my.home.page.com",
"author": {
"name": "Matias Fidemraizer",
"email": "no-email#no-email.com",
"url": "http://some.url.com"
},
"engines": {
"node": ">=0.4.0"
},
"keywords": [
"somekeyword"
],
"license": {
"type": "Apache v2",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"preferGlobal": true,
"repository": {
"type": "git",
"url": "git://github.com/some/repo"
},
"dependencies": {
"somedependency": "*"
}
}
When I try to install the whole module typing npm -g install /path/to/module/folder, npm creates a .cmd file on AppData folder in the default node_modules location for global installations as expected.
But generated code doesn't include node.exe or node:
"%~dp0\node_modules\some-module\bin\some-module.js" %*
... so when I try to execute my some-module module in CMD, PowerShell or whatever, it's executed using Windows Script Host (WSH).
For that reason I thought comparing package.json of some existing module like YUIDocJS would be enough to find out what's causing this problem but I can't figure out what's wrong in my own package.json so it doesn't create the expected global installation.
Thank you in advance for your effort.
Do you have the shebang #!/usr/bin/env node at the top of the file referenced in the bin property of your package.json? Even though the shebang is a *nix specific directive, npm depends on its presence to create the shim for the .cmd

node_modules is not recognized as an internal or external command

I'm trying to write a test automation script using appium, jasmine, and perfecto mobile. I'm using the project cloned from the following URL with my own configuration Appium Javascript Example
The problem is when I execute the npm test command I get the following error
node_modules is not recognized as an internal or external command
This is how the packages.json script looks like:
{
"name": "perfecto_appium_sample",
"version": "1.0.0",
"description": "The following sample shows how to Install an application and use WebDriverIO to automate and test it.<br/> It uses selendroid test application which can be downloaded from [here](https://github.com/PerfectoCode/AppsForSamples/tree/master/selendroid-test-app-0.17.0).",
"main": "perfectoSpec.js",
"scripts": {
"test": "node_modules/webdriverio/bin/wdio wdio.conf.js",
"start": "wdio wdio.conf.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"wdio": "^0.3.3",
"wdio-jasmine-framework": "^0.2.19",
"wdio-mocha-framework": "^0.5.12"
},
"dependencies": {
"wd": "^1.5.0",
"webdriverio": "^4.10.2"
},
"keywords": []
}
you need to provide relative path properly:
"scripts": {
"test": "node ./node_modules/webdriverio/bin/wdio wdio.conf.js",
"start": "wdio wdio.conf.js"
}
Just remove the paths "node_modules/webdriverio/bin/" and simply specify "wdio wdio.conf.js". It should work.

Categories

Resources