Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The programmatic API was removed in npm v8.0.0 #26

Closed
FerrariAndrea opened this issue Feb 22, 2022 · 6 comments
Closed

The programmatic API was removed in npm v8.0.0 #26

FerrariAndrea opened this issue Feb 22, 2022 · 6 comments

Comments

@FerrariAndrea
Copy link

Hi,
I can't init the project, working with $ npm -v: 8.1.2.
Output of $ npm i @arces-wot/wam -g:

npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: @rollup/plugin-node-resolve@6.1.0
npm WARN Found: rollup@2.68.0
npm WARN node_modules/@arces-wot/wam/node_modules/rollup
npm WARN   rollup@"^2.0.0" from @arces-wot/wam@0.5.5
npm WARN   node_modules/@arces-wot/wam
npm WARN     @arces-wot/wam@"*" from the root project
npm WARN   3 more (@rollup/plugin-json, rollup-plugin-commonjs, @rollup/pluginutils)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer rollup@"^1.20.0" from @rollup/plugin-node-resolve@6.1.0
npm WARN node_modules/@arces-wot/wam/node_modules/@rollup/plugin-node-resolve
npm WARN   @rollup/plugin-node-resolve@"^6.0.0" from @arces-wot/wam@0.5.5
npm WARN   node_modules/@arces-wot/wam
npm WARN
npm WARN Conflicting peer dependency: rollup@1.32.1
npm WARN node_modules/rollup
npm WARN   peer rollup@"^1.20.0" from @rollup/plugin-node-resolve@6.1.0
npm WARN   node_modules/@arces-wot/wam/node_modules/@rollup/plugin-node-resolve
npm WARN     @rollup/plugin-node-resolve@"^6.0.0" from @arces-wot/wam@0.5.5
npm WARN     node_modules/@arces-wot/wam
npm WARN deprecated rollup-plugin-commonjs@10.1.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-commonjs.

added 85 packages, and audited 86 packages in 10s

11 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Output of wam init test:

C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\@arces-wot\wam\node_modules\global-npm\index.js:55
      throw e
      ^

Error: The programmatic API was removed in npm v8.0.0
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\index.js:4:9)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\@arces-wot\wam\node_modules\global-npm\index.js:49:15
    at Object.<anonymous> (C:\Users\USER_NAME\AppData\Roaming\npm\node_modules\@arces-wot\wam\node_modules\global-npm\index.js:59:3)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)

After that, in the directory that I run init cmd, nothing is generated, the directory is still void.

@relu91
Copy link
Contributor

relu91 commented Feb 22, 2022

It seems like npm has discontinued the support for programmatic API this is a pity since we can't install packages automatically with npm 8 .... See dracupid/global-npm#7 (comment) and npm/cli#3762 . I'll some do tests to see if we can have a workaround, meanwhile, the only available option is to downgrade to npm 7

relu91 added a commit that referenced this issue Feb 22, 2022
@vinodloha
Copy link

Any alternative for this @relu91 ?

@relu91
Copy link
Contributor

relu91 commented Jun 24, 2022

Any alternative for this @relu91 ?

For wam currently we are catching the exception and kindly ask the user to manually install the packages (i.e., type npm install). If you are asking about the issue of the API not exposed anymore, I still didn't have the bandwidth to experiment with npm 8. I really hope that they will support the API in the future.

@AntonyF-Andreani
Copy link

This is a bad new :(, but with promisify and write in child_process will be an alternative

@boeckMt
Copy link

boeckMt commented Mar 6, 2023

This is a bad new :(, but with promisify and write in child_process will be an alternative

Here is an example that works for me

/**
 * https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback
 * https://stackoverflow.com/a/69296792/10850021
 */
const util = require('util');
const exec = util.promisify(require('child_process').exec);

(async () => {

    try {
       const { stdout, stderr } = await exec('npm pkg get dependencies');
        // do something with the dependencies 
       const dependencies = JSON.parse(stdout);
       ...

       const { stdout: stdout1, stderr: stderr1 } = await exec('npm pkg get peerDependencies -ws');
       // do something with the peerDependencies of all workspaces, e.g. set them to a specific version
       ...

    } catch (e) {
        console.error(e); // should contain code (exit code) and signal (that caused the termination).
    }
})();

@ikarthikng
Copy link

ikarthikng commented May 16, 2023

I ran into an issue when we did a major upgrade to our nestjs application. This is how we were able to solve it.

Before upgrade code:

import * as npm from "npm"

(async () => {

/*Loading all the needed parameters from AWS*/
   
})().then(() => {
     npm.load(() => npm.run(`start:main`))
})

After upgrade code:

import * as child from "child_process"

(async () => {

/*Loading all the needed parameters from AWS*/
   
})().then(() => {
child.spawn("node", ["dist/main"], {
    shell: true,
    stdio: "inherit"
  })
})

used child_process to directly call file instead of depending on npm cli or npm to call that file. I hope this helps someone.

@relu91 relu91 closed this as completed in e60fb6c Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants