help icon indicating copy to clipboard operation
help copied to clipboard

Nodejs 16.x error: The programmatic API was removed in npm v8.0.0

Open mukeshkmr776 opened this issue 3 years ago • 5 comments

Details

I changed my Nodejs. from 14.x to 16.x and getting error:

Error: The programmatic API was removed in npm v8.0.0, stacktrace: Error: The programmatic API was removed in npm v8.0.0
    at Object.<anonymous> (/nodejs16/node_modules/npm/index.js:4:9)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159: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 Object.<anonymous> (/app/service.js:25:15)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)

Unable to understand what is the breaking change in Nodejs 16.x which is causing this issue.

Node.js version

Old Nodejs : 14.17.0 New Nodejs : 16.15.1

Example code

Project code. Can't disclose source.

Operating system

IBM AIX - 7.2

Scope

runtime

Module and version

Not applicable.

mukeshkmr776 avatar Jun 13 '22 10:06 mukeshkmr776

The breaking change is, as indicated by the error message, npm 8. Node.js 14.x has npm 6, while Node.js 16 has npm 8. See this note from the npm team, https://github.com/nodejs/node/issues/40168#issuecomment-923358366.

Even in Node.js 14 the programmatic API for npm is not requirable from the bundled npm without messing around with NODE_PATH (deprecated) or symlinks so this wasn't considered a breaking change for Node.js.

cc @nodejs/npm

richardlau avatar Jun 13 '22 12:06 richardlau

@richardlau Thanks for the information. How to overcome this issue? :( It means, we can't upgrade from Nodejs 14 to Node 16 ? :(

mukeshkmr776 avatar Jun 13 '22 17:06 mukeshkmr776

If you want lower level access to things that npm does, then you may want to switch to using @npmcli/arborist or pacote, depending on what you used to be using the internal API for.

fritzy avatar Jun 13 '22 18:06 fritzy

Where's list of internal API in npm? We don't use require('npm'), but might be the dependencies using them. How to fix this issue? Any suggestions would be highly appreciated.

would npm install again work?

mukeshkmr776 avatar Jun 13 '22 19:06 mukeshkmr776

Where's list of internal API in npm? We don't use require('npm'), but might be the dependencies using them. How to fix this issue? Any suggestions would be highly appreciated.

would npm install again work?

Error stack shows there is a require statement at line 25, this require required a package/module which used programmatic npm api caused the error.

    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/app/service.js:25:15)

Could you search the dependency tree of this package/module to find out which package cause the problem? After find out what package cause the problem, you may either update this package if it has fixed this problem or upstream fix to this package.

F3n67u avatar Jun 14 '22 01:06 F3n67u

Se tiene alguna solucion a este problema ?

anchezj avatar Feb 24 '23 21:02 anchezj

@mukeshkmr776 did you solve it?, please update us if you find any solution, I am getting same error in Nextjs 14.1.4

masnoonJunaid avatar Apr 08 '24 05:04 masnoonJunaid

Project code. Can't disclose source.

Unfortunately, it's hard to debug without any example code. If anyone is experiencing similar issues in the latest version of Node.js, please file a new issue with detailed reproduction steps.

avivkeller avatar Jun 16 '24 15:06 avivkeller