How to tell npm to install from local not git - npm

I have a server without internet access but a local npm. I'm trying to install a Node.js application, and one of the modules points to github. The package is part of one of the dependencies packages.
{
"name": "doccano",
"version": "1.0.0",
"description": "doccano is an open source annotation tools for machine learning practitioner.",
"author": "Hironsan",
"private": true,
"scripts": {
...
"dependencies": {
...
"#toast-ui/vue-editor": "^1.1.1",
...
}
}
Most packages are downloaded from local npm, but some point to github, and then I get the error:
npm install
...
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/seonim-ryu/Squire.git
npm ERR!
npm ERR! ssh: Could not resolve hostname github.com: Name or service not known
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
I can download the repository and upload it to the server, but how can I install the github packages?

Related

Can the NPM registry be removed from package-lock.json file?

I work behind a corporate Firewall, So I have to set a registry in npm like
npm config set registry https://aa-artifactory.abc.com/artifactory/api/npm-repo/
I have now finished building my app and want to deploy on Heroku. However when I try to deploy, the build fails & the below error is shown
-----> Installing dependencies
Installing node modules
npm ERR! code ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! errno ENOTFOUND
npm ERR! network request to https://aa-artifactory.abc.com/artifactory/api/npm-repo/yargs-parser/-/yargs-parser-20.2.9.tgz failed, reason: getaddrinfo ENOTFOUND aa-artifactory.abc.com
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
I think is a natural error since Heroku will not have access to the registry of the company.
I tried to find from where the registry info is being sent & it turns out it is in package-lock.json. I was not aware why we even have package-lock.json!.
Every dependency(even the "indirect" dependencies) has an entry like below & you can see the resolved key with the registry info.
"node_modules/#szmarczak/http-timer": {
"version": "1.1.2",
"resolved": "https://aa-artifactory.abc.com/artifactory/api/npm-repo/#szmarczak/http-timer/-/http-timer-1.1.2.tgz",
"integrity": "sha1-sWZeLEYaLNkvTBu/UNVFTeDUtCE=",
"dev": true,
"license": "MIT",
"dependencies": {
"defer-to-connect": "^1.0.1"
},
"engines": {
"node": ">=6"
}
}
Now, the question is, how can I deploy my app on Heroku.
Should I just remove package-lock.json & just use package.json? Will this work?
Or should i just modify the package-lock.json file? This seems tedious but may be worthwhile if i want to control the exact version of packages.
Please guide.

Can not "npm publish" to internally-hosted npm repository?

I followed Using Nexus 3 as Your Repository – Part 2: npm Packages to set up an internal npm repository.
I'm then able to do this,
$ npm view jsreport dist.tarball
https://registry.npmjs.org/jsreport/-/jsreport-3.0.1.tgz
I have this in my ~/.npmrc file
$ cat ~/.npmrc
//internal_nexus_url:8081/repository/:_authToken=NpmToken.43b77b61-2492-39b8-8150-38555f6b6943
I have this in my /path_to_project/.npmrc file
registry="http://internal_nexus_url:8081/repository/npm-private/_auth=base64_user_pw"
and this in my /path_to_project/package.json file
{
...
"publishConfig": {
"registry": "http://internal_nexus_url:8081/repository/npm-private"
},
...
}
When do an npm publish I get
npm notice === Tarball Details ===
npm notice name: my-package
npm notice version: 2.4.4
npm notice filename: my-package-2.4.4.tgz
npm notice package size: 141.6 MB
npm notice unpacked size: 421.1 MB
npm notice shasum: 09c134ef93ce70e999d62820b5bffc6cf23765f3
npm notice integrity: sha512-X5iqe9DV03MPG[...]TKvNZO4O8ToyQ==
npm notice total files: 17559
npm notice
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /patch/.npm/_logs/2021-11-16T21_48_03_450Z-debug.log
The error file above basically says the same thing. So I follow the instructions, and do
$ npm adduser
$ npm adduser
npm notice Log in on http://internal_nexus_url:8081/repository/exa-npm-private/_auth=base64_user_pw
Username: nexus-user
Password:
Email: (this IS public) nexus#kmha.com
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm ERR! A complete log of this run can be found in:
npm ERR! /path/.npm/_logs/2021-11-16T21_52_29_060Z-debug.log
What's preventing me from publishing to my internal npm repo?
UPDATE:
I modified my ~/.npmrc file to include the information on How should I set _auth in .npmrc when using a Nexus https npm registry proxy? to no avail.

HEROKU: Logging in with another Heroku accnt and deploying fails my build

UPDATE:
I removed the warning by switching bcrypt versions V3 with V1.03. BUT now my passwords don't work. I assume it's because of the different hashing between both versions.
I created a personal Heroku account and uploaded my MERN project without a problem. I then created a 2nd Heroku accnt for work.
I then heroku logout and heroku login with the new account. I then tried uploading the same project with no changes, but keep getting
bcrypt#3.0.2 install /tmp/build_c823e78c1ca132209f395f59cc6e1071/node_modules/bcrypt
node-pre-gyp install --fallback-to-build
// lots of node-pre-gyp ERR! code before finishing with
gyp ERR! cwd /tmp/build_c823e78c1ca132209f395f59cc6e1071/node_modules/bcrypt
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt#3.0.2 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt#3.0.2 install script.
Node v8.12.0
NPM 6.4.1
Git version 2.17.1 (Apple Git-112)
macOS Mojave V 10.14
I use bcrypt 3.0.2 and ran into a similar issue today. Locally I am using Node version 10.11.0, but because I haven't specified it in the package.json, Heroku took a default Node version 8.XX.XX. I set it explicitly for Heroku as the same version as I use locally in my package.json file and then it worked.
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"engines": {
"node": "10.11.0"
},
"scripts": {
...

No compatible version found: grunt-contrib-concat#'node_modules/grunt-contrib-concat'

I recently received website that consists of an index.html, sass files, javascript files and a few configuration files. I tried to run the command npm install in the main project directory and I got the following error.
npm ERR! Error: No compatible version found: grunt-contrib-concat#'node_modules/grunt-contrib-concat'
npm ERR! Valid install targets:
npm ERR! ["0.1.0","0.1.1","0.1.2","0.1.3","0.2.0","0.3.0","0.4.0","0.5.0","0.5.1","1.0.0","1.0.1","0.1.2-rc5","0.1.2-rc6"]
npm ERR! at installTargetsError (/usr/share/npm/lib/cache.js:719:10)
npm ERR! at /usr/share/npm/lib/cache.js:638:10
npm ERR! at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7)
npm ERR! at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 4.4.0-x86_64-linode63
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /var/www/project.com/public_html_staging
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /var/www/project.com/public_html_staging/npm-debug.log
npm ERR! not ok code 0
This is what my package.json looks like
{
"name": "project",
"version": "0.0.0",
"devDependencies": {
"glob": "~4.3.1",
"grunt": "~0.4.1",
"grunt-autoprefixer": "~2.0.0",
"grunt-concat-css": "^0.3.1",
"grunt-contrib-concat": "node_modules/grunt-contrib-concat",
"grunt-contrib-connect": "~0.9.0",
"grunt-contrib-cssmin": "~0.11.0",
"grunt-contrib-imagemin": "^1.0.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-sass": "~0.8.1",
"grunt-contrib-uglify": "~0.7.0",
"grunt-contrib-watch": "~0.6.1"
},
"dependencies": {
"load-grunt-tasks": "~2.0.0"
}
}
I'm really new to the npm command and any related subject matter. How do I begin to troubleshoot this error? Or does anyone know the solution?
The problem was caused by the fact that I was using NodeJS version 0.1 while the project was originally built on a server that had NodeJS v5. Hence the npm didn't have all the right grunt dependencies.
I did the following as root user on my affected server
apt-get purge nodejs
apt-get purge npm
apt-get autoremove // remove any orphan dependences
Once I got rid of everything, I install version 6 of NodeJS as per the nodejs website with these commands:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
The NodeJS already came with it's own npm, so I didn't need to do anything else.
Then when I ran npm install, it properly downloaded all the necessary modules to run my project.

Difficulty solving "sh: <npm package name> command not found" with npm run <npm package name>

I've been adding npm modules to my project for the first time (jshint, optimg, jpgo). I notice that some projects, when I do npm run [name], give a result of "sh: [name]: command not found."
I can't figure out why those don't work, but the other npm installs do. All these are installed locally; I can see the install by looking in the /node_modules folder in my project root and verify them with npm ls.
The latest package that gets this error is html-minify. My package.json looks like this (and validates at http://jsonlint.com/):
{
"name": "npmTest",
"devDependencies": {
"jshint": "latest",
"optimg": "latest",
"jpgo": "latest",
"ycssmin": "latest",
"html-minify": "latest"
},
"scripts": {
"lint": "jshint **.js",
"png": "optimg",
"jpg": "jpgo",
"css": "ycssmin **.css",
"html": "html-minify"
}
}
I tried "html-minify **.html" with the same resulting "not found" error.
Why would I get "sh: [npm package name]: command not found"? I've read the other threads, and because the other modules work, I doubt that I need to add anything to my PATH, or start a server, or install globally.
Fuller error message (for html5-lint):
$ npm run html
> npmTest# html /Users/Steve/Documents/APPS/Test_Apps/npmTest
> html5-lint
sh: html5-lint: command not found
npm ERR! npmTest# html: `html5-lint`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the npmTest# html script.
npm ERR! This is most likely a problem with the npmTest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! html5-lint
npm ERR! You can get their info via:
npm ERR! npm owner ls npmTest
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.1.0
npm ERR! command "node" "/usr/local/bin/npm" "run" "html"
npm ERR! cwd /Users/Steve/Documents/APPS/Test_Apps/npmTest
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Steve/Documents/APPS/Test_Apps/npmTest/npm-debug.log
npm ERR! not ok code 0
so short answer to run npm package commands locally
npm i install cowsay -d
then use
npx cowsay I am working locally
output should be
______
< I am working locally >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
on the other hand installing npm packages globaly on linux has problems with addministrator and node-module location
so best practice to get global packges to work normally is to install NVM first
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
then once nvm is installed install from nvm node
nvm install node
or a specific version
nvm install 12.18.3
now installing global packages and running them is simple
npm install -g cowsay
cowsay I am working globaly
will output
______
< I am working >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
now global packages are working fine and local packages can be run from the directory of the project using npx.
For the command not found issue you're seeing with html-minifier it could have to do with not globally installing the npm package (with a -g) or calling the command by the wrong name (I believe you're calling the package name html-minify when the package is defined as html-minifier)
Would suggest installing the command with a -g:
npm install html-minifier -g
and then running the html-minifier command:
html-minifier --help (to test installation)
html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true
Also for the scripts issue you're observing (where running npm run html is returning command not found)- here is a sample package.json. I ran npm run html (after globally installing html-minifier using the step above) and that runs html-minifier --help:
{
"name": "stackoverflow",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"html": "html-minifier --help"
},
"author": "",
"license": "ISC",
"dependencies": {
"html-minifier": "^4.0.0"
}
}
Github link: https://github.com/kangax/html-minifier
Npm link: https://www.npmjs.com/package/html-minifier
Installation and usage steps provided in the README:
Installation Instructions
From NPM for use as a command line app:
npm install html-minifier -g
From NPM for programmatic use:
npm install html-minifier
From Git:
git clone git://github.com/kangax/html-minifier.git
cd html-minifier
npm link .
Usage
Note that almost all options are disabled by default. For command line usage please see html-minifier --help for a list of available options. Experiment and find what works best for you and your project.
Sample command line: html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true
Node.js
var minify = require('html-minifier').minify;
var result = minify('<p title="blah" id="moo">foo</p>', {
removeAttributeQuotes: true
});
result; // '<p title=blah id=moo>foo</p>'