Babel build program is breaking permission of NPM bin script - node.js

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.

Related

Angular npm link throws 404 while linking local dependency lib

As the title says, creating a link with the dependency (it shows inside my global node folder). However I am using nvm-windows which creates separate folders fore each version which may cause some issues but reading about this issue the env var NVM_SYMLINKS used to fix this.
Env variables contains NVM_SYMLINKS and it points to a nodejs installation at my main drive which according to other issues is fine.
$ npm start
> own-webpage#0.0.0 start C:\PROJECTS\HMR\HKIR\hkir\hmr\bo\frontend
> npm link lib-hkir-common-client-bo && ng serve
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/lib-hkir-common-client-bo - Not found
npm ERR! 404
npm ERR! 404 'lib-hkir-common-client-bo#latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\WORKSTATION\AppData\Roaming\npm-cache\_logs\2022-03-28T09_39_51_833Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! own-webpage#0.0.0 start: `npm link lib-hkir-common-client-bo && ng serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the own-webpage#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\WORKSTATION\AppData\Roaming\npm-cache\_logs\2022-03-28T09_39_51_877Z-debug.log
Running node -v in both directories shows that both of them are using the same versions.
I've tried deleting both node_modules, package-locks, removing the smylink from the main global recreating said symlink. But nothing seems to work.
When creating the link via npm link inside the dependency it prints out the following symlink pattern:C:\Program Files\nodejs\node_modules\lib.hkir.common.client.bo -> C:\PROJECTS\HMR\HKIR\hkir\lib.hkir.common.client.bo which once again according to others is completely fine.
How can I fix the issue so my project sees and uses the linked dependency?
Thanks.

how to fix npm error in Mac in visual studio code

How do I fix this error?
USER#Bahus-MacBook-Air metaplex-master % npm --version
8\.5.2
USER#Bahus-MacBook-Air metaplex-master % npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/USER/Desktop/solana devnet/metaplex-master/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/USER/Desktop/solana devnet/metaplex-master/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/USER/.npm/\_logs/2022-03-24T13_07_17_630Z-debug-0.log
How do I fix this npm installation error in visual studio code in Mac?
The error message says that the path where you are executing npm i command doesn't have package.json file.
Make sure to change the path to the place where the package.json file is located.
I'm assuming you are trying this project https://github.com/metaplex-foundation/metaplex
And you are probably running npm install in the main directory. But if you read the instalation documentation which you definitely should, then you would see cd metaplex/js which means you need to run npm install within the ./js folder since that's where the package.json is, which is required by npm install command.

Parcel command not found

In my project, I use Parcel to bundle everything. Now, I am at the point where I need to deploy my app.
I clone my git repo with my React app and I put in the Node server.
I tried every command possible to install parcel, but I always get the following error :
> pp-react#0.1.0 build /home/volodymk/react
> parcel build index.html
sh: parcel: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! pp-react#0.1.0 build: `parcel build index.html`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the pp-react#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/volodymk/.npm/_logs/2020-01-12T19_26_22_634Z-debug.log
How can I fix this ?
To run any installed node package (not just Parcel), use npx, the utility command shipped with npm. It executes packages that come with a runtime command in your node_modules/packagename/.bin directories.
As in npx parcel build index.html
More information available in the npx readme.

npm run npm bin from within the same package

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?

npm install from git repo fails with ENOENT

I am trying to install one of my own packages as follows
npm install --save gfarrell/state.js
and I'm getting the following errors (full log here):
npm ERR! addLocal Could not install gfarrell/state.js
npm ERR! Error: ENOENT, stat 'gfarrell/state.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! System Darwin 13.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "--save" "gfarrell/state.js"
npm ERR! cwd /Users/gideon/Code/PresenceMonitor
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.10
npm ERR! path gfarrell/state.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/gideon/Code/PresenceMonitor/npm-debug.log
npm ERR! not ok code 0
Now I've tried various solutions including:
npm cache clean
sudo npm cache clean
rm -rf ~/.npm
sudo npm install --save gfarrell/state.js
npm install --save git://github.com/gfarrell/state.js.git
but nothing has changed the error output. I can't see anything wrong with the module's package.json, and I haven't added anything to my local package.json either. I actually tried installing this package on an earlier version and it worked fine, so I just don't understand what is going wrong.
Needless to say, it's all rather frustrating. Is there something else going on that I'm just not seeing?
This is most probably an authentication issue. You should add --verbose to the install command to se more output. You should see this line in your console output when running with verbose on:
npm ERR! git clone git#github.com:gfarrell/state.js Permission denied (publickey).
Check if you are authenticated to Github using the following command:
ssh -T git#github.com
When you are authenticated correctly you should see the following output:
Hi gfarrell! You've successfully authenticated, but GitHub does not provide shell access.
Github has a great guide on SSH keys as well as how to solve common errors.
Fix your Github authentication and the npm install will start working.
I had a similar issue myself. Because the last "ok" line of the verbose output started with "addRemoteGit", I traced the issue to a function named addRemoteGit in the npm source file cache.js (in v1.4.9, it has now been moved into add-remote-git.js). By adding a call to log.verbose(p), I found out npm could not write to ~/.npm/_git-remotes/.
Basically it was a permission problem: my ~/.npm directory contained files & directories owned by root. I solved the issue by simply running:
sudo find ~/.npm -exec chown $USER:$USER {} \;

Resources