Nodejs 16.x error: The programmatic API was removed in npm v8.0.0
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.
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 Thanks for the information. How to overcome this issue? :( It means, we can't upgrade from Nodejs 14 to Node 16 ? :(
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.
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?
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 installagain 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.
Se tiene alguna solucion a este problema ?
@mukeshkmr776 did you solve it?, please update us if you find any solution, I am getting same error in Nextjs 14.1.4
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.