Tag Archives: npm

Unable when downloading NPM_ TO_ VERIFY_ LEAF_ Signature error

Recently, after the system has been re installed and the node has been re installed, I don’t know what happened. NPM can’t be downloaded,
it’s reported as unable_ TO_ VERIFY_ LEAF_ Signature error

As shown in the figure, this sentence is displayed

npm ERR! code UNABLE_TO_VERIFY_LEAF_SIGNATURE

By default, NPM adopts the HTTPS protocol. In fact, our package has no security

In addition, the problem of GFW in using HTTPS leads to the error of NPM install, that is to say, NPM is blocked

(1) Turn off strict SSL, that is, turn off the HTTPS of NPM and use HTTP protocol instead

npm config set strict-ssl false

When we need to re enable it, set it again:

npm config set strict-ssl true

(2) We can also reset the access address of NPM

npm config set registry "http://registry.npmjs.org/"

How to Use Yarn instead of NPM

1. About yarn

Yarn is a new JS package management tool jointly launched by Facebook, Google, exponent and tilde. As written in the official document, yarn appears to make up for some defects of NPM

2. Yarn advantage

1. Fast

The fast speed mainly comes from the following two aspects:

1.1 parallel installation: both NPM and yarn will perform a series of tasks when installing packages. NPM is to execute each package according to the queue, that is to say, it must wait until the current package installation is completed before the subsequent installation can continue. Yarn performs all tasks synchronously, which improves performance

1.2. Offline mode: if a software package has been installed before and is retrieved from the cache when using yarn to install it again, you don’t need to download it from the network like NPM

2. Unified installation version

In order to prevent pulling different versions, yarn has a lock file that records the version number of the module exactly installed. Each time a new module is added, yarn will create (or update) the yarn. Lock file. This ensures that every time you pull the same project dependency, you use the same module version. NPM actually has a way to use the same version of packages everywhere, but the developer needs to execute the NPM shrinkwrap command. This command will generate a lock file. When NPM install is executed, the lock file will be read first. This is the same reason that yarn reads yarn.lock file. The difference between NPM and yarn is that yarn generates such a lock file by default, while NPM generates the npm-shrinkwrap.json file through the shrinkwrap command. Only when this file exists will the packages version information be recorded and updated

3. More concise output

The output information of NPM is lengthy. When NPM install is executed, the command line will print out all the installed dependencies. In contrast, yarn is too concise: by default, it combines Emoji to print out the necessary information intuitively and directly, and also provides some commands for developers to query for additional installation information

4. Multi registration source processing

All dependent packages, no matter how many times they are indirectly associated and referenced by different libraries, will only be installed from one registered source, either NPM or bower, to prevent confusion and inconsistency

5. Better semantics

Horn changes the names of some NPM commands, such as horn add/remove, which is clearer than the original NPM install/install

3.Yarn installation

npm install -g yarn

4.Yarn command

1. View version

yarn -v

2. Create project

yarn init

3. Installation dependency

yarn or yarn install

4. Run the script

yarn run 

5. Package build

yarn build

6. Display a package information

yarn info 

7. Lists the dependencies for the current project

yarn list

8. Displays the current configuration

yarn config list

9. Lists each package that has been cached

sudo yarn cache list 

10. Clear cache

sudo yarn cache clean

5. NPM Comparison

Npm Yarn
npm install yarn
npm install react –save yarn add react
npm uninstall react –save yarn remove react
npm install react –save-dev yarn add react –dev
npm update –save yarn upgrade

Root permission NPM global installation (- G) will still have insufficient permissions. Please know the parameter unsafe perm

Environmental description

ganiks@ganiks-ubuntu-trusty-64:/ganiks/parse-server$ npm -v
6.5.0
ganiks@ganiks-ubuntu-trusty-64:/ganiks/parse-server$ node -v
v10.15.0

Problem description

Install and deploy parseserver service

root@ganiks-ubuntu-trusty-64:/ganiks/parse-server# npm install -g parse-server mongodb-runner

The first exception was encountered

> [email protected] install /usr/local/lib/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/lib'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp"
gyp WARN install got an error, rolling back install

Complete error information:

> [email protected] install /usr/local/lib/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for [email protected] and [email protected] (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/lib'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/10.15.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node-gyp'
gyp ERR! System Linux 3.13.0-164-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/usr/local/lib/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:962:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
node-pre-gyp ERR! System Linux 3.13.0-164-generic
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
node-pre-gyp ERR! node -v v10.15.0
node-pre-gyp ERR! node-pre-gyp -v v0.12.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install 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!     /root/.npm/_logs/2019-01-17T08_54_06_070Z-debug.log
  

How to Solve

npm install Adding parameters–unsafe-perm

root@ganiks-ubuntu-trusty-64:/ganiks/parse-server# sudo npm install -g parse-server mongodb-runner --unsafe-perm

References

https://github.com/nodejs/node-gyp/issues/454

https://github.com/nfarina/homebridge/issues/405#issuecomment-164803485

If npm detects it is running as root it drops to a non-privileged user which then doesn’t have permissions to write to/root/.node-gyp.

The–unsafe-permoption stops it from changing user.

nvm doesn’t have this problem when not using sudo because it stores everything under the current users’ home directory.

https://docs.npmjs.com/misc/config#unsafe-perm–unsafe-perm

See the official documentation for an explanation

unsafe-perm
Default: false if running as root, true otherwise
Type: Boolean
Set to true to suppress the UID/GID switching when running package scripts.

If set explicitly to false, then installing as a non-root user will fail.

Add:

There is no need to install parse-server globally (-g), install it to the local directory and you will not encounter the problems in this article.

vagrant@ganiks-ubuntu-trusty-64:~/parse-server-advanced$ npm install parse-server
npm WARN deprecated [email protected]: stop using this version

> [email protected] install /home/vagrant/parse-server-advanced/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download
[bcrypt] Success: "/home/vagrant/parse-server-advanced/node_modules/bcrypt/lib/binding/bcrypt_lib.node" is installed via remote

> [email protected] postinstall /home/vagrant/parse-server-advanced/node_modules/parse-server
> node -p 'require("./postinstall.js")()'


                  1111111111
               1111111111111111
            1111111111111111111111
          11111111111111111111111111
        111111111111111       11111111
       1111111111111             111111
      1111111111111   111111111   111111
      111111111111   11111111111   111111
     1111111111111   11111111111   111111
     1111111111111   1111111111    111111
     1111111111111111111111111    1111111
     11111111                    11111111
      111111         1111111111111111111
      11111   11111  111111111111111111
       11111         11111111111111111
        111111     111111111111111111
          11111111111111111111111111
            1111111111111111111111
              111111111111111111
                  11111111111


        Thanks for installing parse 🙏
  Please consider donating to our open collective
      to help us maintain this package.

  👉 https://opencollective.com/parse-server

added 356 packages from 381 contributors in 51.675s

NPM Command Error: Allocation failed – JavaScript heap out of memory

Error occurred when executing NPM command:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

The reason is that there is not enough memory in JavaScript heap. Node is based on V8 engine. When using memory through JavaScript in node, only part of memory can be used (about 1.4 GB in 64 bit system). If memory is not enough, you can use the following methods to relax the default memory limit of V8.

Method 1:

add parameters  — max_ old_ space_ size=4096

npm run start --max_ old_ space_ size=4096

Method 2:

modify the CMD file

In the directory node_ Open ng.cmd and ngc.cmd files under modules /. Bin, and add  — max_ old_ space_ size=4096

Method 3:

through the increase memory limit plug-in

Install plug-in: NPM install – G increase memory limit

Execute command: NPX cross env limit = 4096 increase memory limit

Through the log, we can find that it will add the — Max old space size = 4096 parameter to all the places where the node command is executed

WebPack Task Runner

https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebPackTaskRunner

New to WebPack?

You may want to check out the article How to integrate WebPack into Visual Studio 2015 by Ilya Pirozhenko

Install WebPack

In order to use this extension, you must have WebPack installed globally or locally in your project.

Use npm to install it globally by typing the following in a command line:

npm install webpack -g

To use the server functionality you also need to install webpack-dev-server like so:

npm install webpack-dev-server -g

If you wish to use babel to run WebPack, you must first install it locally in your project:

npm install babel-core --save-dev

Item Template

You can easily add a new webpack.config.js file to your project from the Add New Item dialog.

Just search for “webpack”.

Unexpected pit of webpack command not found – starting from node

Write a note for yourself:

For a long time

Do the following

npm install webpack -g

Because Xiaobai doesn’t understand the principle, he executed it many times, and the result is still as the title

I searched the Internet for a long time and tried various methods

Obviously, the installation is successful

A sudden awakening

When installing node, the compiled file is used

Then use the soft link ln to the system bin to configure the environment

Results when webpack was installed, although the installation was successful, it went to the bin of node instead of the system environment variable

So it failed all the time.

The simplest solution: make a link to the system environment.

In addition: remember that when you configure the node next time, you can directly put it in the location of the system environment variable $path, and there won’t be so many things.

This is also according to the online installation tutorial, operation, do not understand the principle of the pit

ln -s /software/node-v10.16.0-linux-x64/bin/webpack /usr/local/bin/

npm install -g webpack-cli