Why i cant run npm in ruby console, but in node console works good? - ruby

i need to run npm in ruby console to run grunt with compass, but when i typing npm in ruby console says "npm is not a command" but when i typing in node console works good. some help? thanks!

[I] need to run npm in ruby console
The #system method, "Executes command… in a subshell.", see: http://ruby-doc.org/core-2.2.0/Kernel.html#method-i-system
$ irb
irb(main):001:0> system('npm')
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
help, help-search, i, init, install, install-test, it, link,
list, ln, logout, ls, outdated, owner, pack, ping, prefix,
prune, publish, rb, rebuild, repo, restart, root, run,
run-script, s, se, search, set, shrinkwrap, star, stars,
start, stop, t, tag, team, test, tst, un, uninstall,
unpublish, unstar, up, update, v, version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/Users/dev/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#3.8.9 /usr/local/lib/node_modules/npm
=> false
irb(main):002:0>
Alternatively, backticks (`cmd`) return "the standard output of running cmd in a subshell.", see: http://ruby-doc.org/core-2.2.0/Kernel.html#method-i-60
$ irb
irb(main):001:0> puts `npm`
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
help, help-search, i, init, install, install-test, it, link,
list, ln, logout, ls, outdated, owner, pack, ping, prefix,
prune, publish, rb, rebuild, repo, restart, root, run,
run-script, s, se, search, set, shrinkwrap, star, stars,
start, stop, t, tag, team, test, tst, un, uninstall,
unpublish, unstar, up, update, v, version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/Users/dev/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#3.8.9 /usr/local/lib/node_modules/npm
=> nil
irb(main):002:0>

Related

`yarn set version from sources` results in "Unrecognized or legacy configuration settings found: changesetIgnorePatterns"

Can't seem to install yarn from sources and I'm not sure how to even debug this sort of thing.
Things I've tried:
homebrew nodejs and yarn
nodejs from official pkg
From the docs I've read, changesetIgnorePatterns should be a valid configuration setting so the only thing I can think of is yarn is reporting v2.4.0 but somehow utilizing an older version when it runs.
% node -v
v15.10.0
% npm -v
7.6.0
% yarn -v
2.4.0
% yarn set version from sources
➤ YN0000: Fetching the latest commits
$ git fetch origin master --force
$ git reset --hard FETCH_HEAD
$ git clean -dfx
➤ YN0000: Building a fresh bundle
Usage Error: Unrecognized or legacy configuration settings found: changesetIgnorePatterns - run "yarn config -v" to see the list of settings supported in Yarn (in /private/var/folders/3y/zswk9wjs4b19pyyvyymgmnzh0000gn/T/yarnpkg-sources/d0a670/.yarnrc.yml)
$ yarn run [--inspect] [--inspect-brk] <scriptName> ...
➤ YN0001: Error: Child "yarn" exited with exit code 1
at ChildProcess.<anonymous> (/Users/frankjmattia/.yarn/releases/yarn-berry.cjs:2:403919)
at ChildProcess.emit (node:events:378:20)
at maybeClose (node:internal/child_process:1067:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
➤ YN0000: Failed with errors in 1s 120ms
Any help or direction in how to troubleshoot would be greatly appreciated.
While I had already deleted .yarn, .yarnrc, and .yarnrc.yml multiple times, after updating to yarn 2.4.1 it finally worked.
I still do not know if this was my own fault or if something had actually changed with yarn, but my problem is now solved. Thank you to whoever upvoted the question, I'm sorry I couldn't produce a more satisfactory answer.
What fixed for me was making sure that the project directory isn't the home directory. Which is often the case when working with Dockerfiles - https://github.com/yarnpkg/berry/issues/2187

How to fix EACCES: permission denied, open '/Users/.... when installing gatsby-cli

I'm setting up Gatsby and get stuck at the beginning.
When i write npx/npm install global gatsby-cli in the terminal -
Alems-MacBook-Pro:~ alemkahrobek$ npm install -g gatsby-cli i see this:
/usr/local/bin/gatsby -> /usr/local/lib/node_modules/gatsby-cli/lib/index.js
gatsby-telemetry#1.0.4 postinstall /usr/local/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry
node src/postinstall.js
gatsby-cli#2.5.4
added 225 packages from 131 contributors in 13.617s.
If i check the version of gatsby i get this:
Alems-MacBook-Pro:~ alemkahrobek$ gatsby -v
/usr/local/lib/node_modules/gatsby-cli/node_modules/configstore/index.js:49
throw error;
^
Error: EACCES: permission denied, open '/Users/alemkahrobek/.config/gatsby/config.json'
You don't have access to this file.
at Object.openSync (fs.js:439:3)
at Object.readFileSync (fs.js:344:35)
at Configstore.get all [as all] (/usr/local/lib/node_modules/gatsby-cli/node_modules/configstore/index.js:31:25)
at new Configstore (/usr/local/lib/node_modules/gatsby-cli/node_modules/configstore/index.js:25:48)
at new Store (/usr/local/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry/lib/store.js:28:51)
at new EventStorage (/usr/local/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry/lib/event-storage.js:24:50)
at new AnalyticsTracker (/usr/local/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry/lib/telemetry.js:32:50)
at Object.<anonymous> (/usr/local/lib/node_modules/gatsby-cli/node_modules/gatsby-telemetry/lib/index.js:7:18)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10).
Now if i try to make a new project like:
gatsby new example
i get this:
Alems-MacBook-Pro:~ alemkahrobek$ npm gatsby new example
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/Users/alemkahrobek/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#6.9.0 /usr/local/lib/node_modules/npm
Alems-MacBook-Pro:~ alemkahrobek$ npm help config
NPM-CONFIG(1) NPM-CONFIG(1)
NAME
npm-config - Manage the npm configuration files
SYNOPSIS
npm config set <key> <value> [-g|--global]
npm config get <key>
npm config delete <key>
npm config list [-l] [--json]
npm config edit
npm get <key>
npm set <key> <value> [-g|--global]
aliases: c
DESCRIPTION
npm gets its config settings from the command line, environment vari-
ables, npmrc files, and in some cases, the package.json file.
See npm help 5 npmrc for more information about the npmrc files.
See npm help 7 npm-config for a more thorough discussion of the mechanisms involved.
The npm config command can be used to update and edit the contents of
the user and global npmrc files.
Sub-commands
Config supports the following sub-commands:
set
npm config set key value
Sets the config key to the value.
If value is omitted, then it sets it to "true".
get
npm config get key
Echo the config value to stdout.
list
npm config list
Show all the config settings. Use -l to also show defaults. Use --json
to show the settings in json format.
delete
npm config delete key
Deletes the key from all configuration files.
edit
npm config edit
Opens the config file in an editor. Use the --global flag to edit the
global config.
SEE ALSO
o npm help 5 folders
o npm help 7 config
o npm help 5 package.json
o npm help 5 npmrc
For Ubuntu users who experience the same problem, I've solved it giving the right permissions on the specified folder:
chown -R $USER:$USER /home/$USER/.config/gatsby
Check out the official page on npmjs.com: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
I would definitely the first option on that page. nvm is pretty awesome: https://github.com/creationix/nvm

Gitlab runner stop after npm install

For using the pipeline in Gitlab, i've created the following .gitlab-ci.yml file:
image: node:8.2.1
cache:
paths:
- node_modules/
TestIt:
script:
- npm install
- '/node_modules/#angular/cli/bin/ng test --single-run=true --browsers PhantomJS --watch=false'
When the runner start the job it is doing the npm install successfully but by that it ends. It doesn't continue to the second script (like it ignores it from some reason).
This is the output:
What can be the cause for that?
If you are on windows, you probably ran into this problem (nothing else executing after a "npm" command):
https://gitlab.com/gitlab-org/gitlab-runner/issues/2730
TL;DR: Use call npm install instead of npm install, then the second command will execute too. Downside: Then your CI config is not platform-independent anymore.
I still didn't found the reason why this happens but as A workaround After a long search instead of using ng test, i'm using npm test, like that:
TestIt:
script:
- npm test
in
Karma.config.js
I changed from autoWatch: true to false and from singleRun: false to true to prevent continuous testing.
I took out the - npm install

NPM has stopped working on Windows 7 64bit, hangs on install/update

At some point my version of NPM stopped working. It seems to have happened when I tried to update npm (from 1.4 shipping with node to a modern 2.x version) a few weeks ago and has steadily gotten worse. I had to change the Environment variable to point to my npm directory before my node directory (to pick up the new version of npm), at that point everything just stopped working. I switched the environment variable back, and then updates would just hang. But strangely when I tried to debug it and add a --verbose to the command the update would work most of the time. Sometimes they hung on the
npm http GET https://registry.npmjs.org/PACKAGE_NAME
but most of the time they worked. This now happens with the old version of NPM (1.4.1) and the new version that I installed (2.1.17), everything always fails on a GET command (usually but not always the first one). I have hit cache-clear, I have wiped out the temp directory, I have tried wiping out %APPDATA/roaming/npm/, and reinstalling everything. I have no proxy in place, but I have run:
npm config set proxy
to set the proxy to blank. I have set the registry to http (rather than https) and set strict-ssl to false. I have uninstalled and reinstalled nodejs, to no luck. I have tried running the commands from an admin cmd prompt rather than a normal command prompt all to no avail. I've run out of ideas, and really need NPM to work...
Below is the output of trying to install grunt-cli after clearing out the %APPDATA/roaming/npm directory:
C:\Users\Kris Erickson>npm install -g grunt-cli --verbose
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
npm verb cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli 'install',
npm verb cli '-g',
npm verb cli 'grunt-cli',
npm verb cli '--verbose' ]
npm info using npm#1.4.28
npm info using node#v0.10.35
npm verb node symlink C:\Program Files\nodejs\\node.exe
npm verb cache add [ 'grunt-cli', null ]
npm verb cache add name=undefined spec="grunt-cli" args=["grunt-cli",null]
npm verb parsed url { protocol: null,
npm verb parsed url slashes: null,
npm verb parsed url auth: null,
npm verb parsed url host: null,
npm verb parsed url port: null,
npm verb parsed url hostname: null,
npm verb parsed url hash: null,
npm verb parsed url search: null,
npm verb parsed url query: null,
npm verb parsed url pathname: 'grunt-cli',
npm verb parsed url path: 'grunt-cli',
npm verb parsed url href: 'grunt-cli' }
npm verb lock grunt-cli C:\Users\Kris Erickson\AppData\Roaming\npm-cache\671ef8ac-grunt-cli.lock
npm verb addNamed [ 'grunt-cli', '' ]
npm verb addNamed [ null, '*' ]
npm verb lock grunt-cli# C:\Users\Kris Erickson\AppData\Roaming\npm-cache\d63f3d0b-grunt-cli.lock
npm verb request where is /grunt-cli
npm verb request registry https://registry.npmjs.org/
npm verb request id dc44ca4b260df8c3
npm verb url raw /grunt-cli
npm verb url resolving [ 'https://registry.npmjs.org/', './grunt-cli' ]
npm verb url resolved https://registry.npmjs.org/grunt-cli
npm verb request where is https://registry.npmjs.org/grunt-cli
npm info trying registry request attempt 1 at 13:36:28
npm http GET https://registry.npmjs.org/grunt-cli
/
Note: the spinner never stops (at least I have left it 10 minutes and nothing happened).
It looks like you may have installed a new npm but it is not actually being used (or did you revert back to 1.4.28?)
In either case, try following the directions here https://github.com/npm/npm/wiki/Troubleshooting#upgrading-on-windows for updating to the latest npm on Windows. Latest is currently 2.4.1. I recommend using Option 3.
Then try running your npm install command with maximum verbosity:
npm -ddd install -g grunt-cli
and upload your logfile as a gist https://gist.github.com either here or as a new issue at https://github.com/npm/npm/issues, and we'll help you get this sorted out.
The version number you're using doesn't comply with the semantic versionning convention npm uses: you need to specify a MAJOR.MINOR.PATCH version number.
You can either:
Use the 0.2.x notation to specify that you don't care what patch version you use, as long as the major.minor matches
Use the ~0.2.0 notation to specify that you don't care what patch version you use, as long as the major.minor matches
Read npm's documentation and semver's documentation for other possibilities...
Hope This helps.
I am running node in windows 8.1. This issue popped up on a new machine build and I searched for hours for a resolution with no success. Finally. in desperation I used fiddler in an attempt to see what calls were being made by npm AND magically the problems went away.
On further investigation I found that npm appears to require two windows environment variables to be set:
Try the following in a command prompt before running npm (Note: if you are actually behind a proxy then replace the empty quotes with your proxy address):
Setx http_proxy ""
Setx https_proxy ""

calling npm from webstorm commad line tool

Im just starting with grunt in webstorm (on windows) and can't call npm (node plugin is installed and enabled, node.exe is in the system path).
npm init
what command line tool outputs:
module.js:340
throw err;
^
Error: Cannot find module 'C:\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Process finished with exit code 8
Thanks
configure NPM with command line in Webstorm:
Webstorm 6 , you need to add command line support plugin :
File > Setting > IDE Settings > Plugins > Command Line Tool Support
once you added to webstorm then
File > Settings > Project Settings > Command Line Tool Support
click '+' to add >
in popup window
Tool Path : C:\Program Files\nodejs\npm.cmd
Alias: npm (or whatever you like)
visibility: select whatever you like
then > OK >
Apply > OK
in webstorm > Tools > Run Command > or (Coomand Line Tools Console)
type command in bottom bar: npm
you will see result something like
C:\Program Files\nodejs\npm.cmd
Usage: npm
where is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, repo, restart, rm,
root, run-script, s, se, search, set, show, shrinkwrap,
star, stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, version,
view, whoami
npm -h quick help on
npm -l display full usage info
npm faq commonly asked questions
npm help search for help on
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\kpatel.npmrc
or on the command line via: npm --key value
Config info can be viewed via: npm help config
npm#1.3.8 C:\Program Files\nodejs\node_modules\npm
Process finished with exit code 0 at 14:32:10.
Execution time: 794 ms.

Resources