Spawn NPM Enoent Workaround

Source: Internet
Author: User
Exports.install = function (ProjectPath, PackageName, save, Dev) {
  const NPM = ' NPM '
  const args = [' Install ']
  Args.push (PackageName)
  if (save) Args.push ('--save ')
  if (dev) args.push ('--save-dev ')
  var ls = require (' Child_process '). Spawn (NPM, args, {
    //stdio: ' Inherit ',
    cwd:projectpath
  })
  Ls.stdout.on (' data ', function (data) {
    Console.log (' stdout: ' + data)
  })
  Ls.stderr.on (' Data ', function (err) {
    Console.log (' stderr: ' + Err)
  })
  ls.once (' Close ', function () {
    console.log (' Install success ... ')
  })
}

Execute NPM Command and will report the following error
cause of error: NPM's execution name is different under Windows Workaround:

  var ls = require (' child_process '). Spawn (Process.platform = = = ' Win32 '?) ' Npm.cmd ': npm, args, {
    //stdio: ' Inherit ',
    cwd:projectpath
  })
PackageUtil.test.js
' Use strict '
const PATH = require (' path ')
const PACKAGEUTIL = require ('. /dist/packageutil ')
const P = path.resolve (__dirname, ' ... ')

/** perform npm install Koa-markdown--save-dev**/
packageutil.install (P, ' Koa-markdown ', True, True) 

/** perform NPM Install Koa-markdown--save**/

Uncomment //stdio: ' Inherit ', remove Stdout.on and Stderr.on

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.