mjeanroy / bower-npm-resolver

Use npm as a registry for your bower dependencies
MIT License
39 stars 13 forks source link

Doesn't work with Node 16 #481

Open danners opened 2 years ago

danners commented 2 years ago

The new npm version shipping with node 16 seems to have changed some thinks required by npm-resolver:

Stack trace: NestedError: Could not require module 'npm' at requireg (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower-npm-resolver\node_modules\requireg\lib\requireg.js:14:11) at Object. (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower-npm-resolver\dist\npm_load.js:28:11) 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 Object. (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower-npm-resolver\dist\npm\versions.js:30:15) at Module._compile (node:internal/modules/cjs/loader:1101:14) Caused By: Error: The programmatic API was removed in npm v8.0.0 at Object. (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 requireg (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower-npm-resolver\node_modules\requireg\lib\requireg.js:12:12) at Object. (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower-npm-resolver\dist\npm_load.js:28:11) at Module._compile (node:internal/modules/cjs/loader:1101:14)

Console trace: Error at StandardRenderer.error (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\renderers\StandardRenderer.js:88:37) at Logger. (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\bin\bower.js:113:30) at Logger.emit (node:events:390:28) at Logger.emit (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\node_modules\bower-logger\lib\Logger.js:29:39) at C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\commands\index.js:49:24 at _rejected (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\node_modules\q\q.js:864:24) at C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\node_modules\q\q.js:890:30 at Promise.when (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\node_modules\q\q.js:1142:31) at Promise.promise.promiseDispatch (C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\node_modules\q\q.js:808:41) at C:\Users\Administrator\AppData\Roaming\npm\node_modules\bower\lib\node_modules\q\q.js:624:44 System info: Bower version: 1.8.12 Node version: 16.13.0 OS: Windows_NT 10.0.17763 x64

ernstki commented 2 years ago

The key part is

 Caused By: Error: The programmatic API was removed in npm v8.0.0

So for those who arrive at this issue looking for a workaround, downgrading to NPM 7.x is one possible workaround. That's what I resorted to in the end.

On my platform—macOS with MacPorts—I can choose the NPM version independent of the Node version, to a limited extent. Your situation may not be as flexible, particularly if you are getting an all-in-one package from nodejs.org.

Even though the change was merged in October 2021, it might be helpful to keep an eye on npm/cli#3762 (the PR that dropped support for this API) for discussions of workarounds. Or just if you want to commiserate with others affected by the change.

References:

mjeanroy commented 2 years ago

Thanks @ernstki, I don't know how to solve this issue yet, except by re-implementing how to fetch packages from scratch :/

ernstki commented 2 years ago

Oh, no hard feelings. This is a tough one.

Mostly wanted to document a workaround here so I can refer back to this issue as my "notes" next time I run into this problem. :)

longevitytina commented 1 year ago

Hiya, any updates on this? Just tried to update to Node 18, same issue as original with npm -v 9.3.1 Caused By: Error: The programmatic API was removed in npm v8.0.0 😢

kemrop commented 1 year ago

Tagging along, running into the same issue. Node 16.19.1 npm v8.19.3

ibcooley commented 1 year ago

@kemrop I've just worked to get this working for our node instance. we're moving to the latest LTS, which is Node 18. You could try pulling the source code from here, or adding it to your node packages, and see if it works for you.

npm install https://github.com/ibcooley/bower-npm-resolver

@mjeanroy I've created a pull request for these changes to be merged into the master repository.

kemrop commented 1 year ago

@ibcooley, Thanks this worked for me.