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

[BUG] npm.load does not accept any options. Only callback #2137

Closed
slonkazoid opened this issue Nov 6, 2020 · 7 comments
Closed

[BUG] npm.load does not accept any options. Only callback #2137

slonkazoid opened this issue Nov 6, 2020 · 7 comments
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release

Comments

@slonkazoid
Copy link

slonkazoid commented Nov 6, 2020

Current Behavior:

npm.load does not accept any options. Only callback.

Expected Behavior:

npm.load actually recognizing my specified options and using them.

Steps To Reproduce:

steps to reproduce the behavior:

  1. In this environment...
  2. With the provided config...
  3. Run
const npm = require("npm");
npm.load({ loglevel: "silent" }, () => {
    console.log("npm loaded");
});
// TypeError: must call as: npm.load(callback)
  1. See error...

Environment:

  • OS: Linux Mint 20 Ulyana
  • Node: v14.15.0
  • npm: 6.4.12

What the .d.ts has to say about it:

    export interface Static extends NodeJS.EventEmitter {
        config: Config;
        commands: Commands;
        rollbacks: any[];
        spinner: Spinner;
        fullList: string[];
        abbrevs: Dictionary<string>;

        prefix: string;
        bin: string;
        globalBin: string;
        dir: string;
        globalDir: string;
        root: string;
        cache: string;
        tmp: string;


        load(cli: ConfigOptions): void; // Throws error
        load(callback: SimpleCallback<Config>): void; // Works
        load(cli: ConfigOptions, callback: SimpleCallback<Config>): void; // Throws error

        deref(command: string): string;
    }

Temporary Workaround

Note that with this workaround you can't install multiple modules in one line

const { exec } = require("child_process");
exec("npm <command> <options>");
@slonkazoid slonkazoid added Bug thing that needs fixing Needs Triage needs review for next steps Release 6.x work is associated with a specific npm 6 release labels Nov 6, 2020
@slonkazoid
Copy link
Author

Can't edit the title, too late. Hope you don't ignore this.

@ljharb
Copy link
Contributor

ljharb commented Nov 6, 2020

Have you tried with npm v7.0.9?

@darcyclarke darcyclarke changed the title [BUG] <title> [BUG] npm.load does not accept any options. Only callback Nov 6, 2020
@slonkazoid
Copy link
Author

Have you tried with npm v7.0.9?

Yes, and it still doesn't work

@GaelicGrime
Copy link

not sure this is related, I am getting the same error when I try to do anything with apm and atom in general that would involve calling npm at some point, and I have not seen issues with npm directly, this thread is the first result of my search to find answers

what information would I need to provide

` will@willdesk /home/will/drive/sync/mine/important 20201114.222329
❯❯❯ apm outdated
/usr/lib/node_modules/npm/lib/npm.js:127
throw new TypeError('must call as: npm.load(callback)')
^

TypeError: must call as: npm.load(callback)
at Object.load (/usr/lib/node_modules/npm/lib/npm.js:127:13)
at loadNpm (/usr/lib/node_modules/atom-package-manager/lib/request.js:16:16)
at configureRequest (/usr/lib/node_modules/atom-package-manager/lib/request.js:20:12)
at Object.get (/usr/lib/node_modules/atom-package-manager/lib/request.js:41:14)
at Upgrade.module.exports.Upgrade.getLatestVersion (/usr/lib/node_modules/atom-package-manager/lib/upgrade.js:123:22)
at /usr/lib/node_modules/atom-package-manager/lib/upgrade.js:222:26
at /usr/lib/node_modules/atom-package-manager/node_modules/async/lib/async.js:227:13
at replenish (/usr/lib/node_modules/atom-package-manager/node_modules/async/lib/async.js:179:21)
at /usr/lib/node_modules/atom-package-manager/node_modules/async/lib/async.js:196:15
at _asyncMap (/usr/lib/node_modules/atom-package-manager/node_modules/async/lib/async.js:226:9)

will@willdesk /home/will/drive/sync/mine/important 20201114.222431
❯❯❯

will@willdesk /home/will/drive/sync/mine/important 20201114.222431
❯❯❯npm version
{
npm: '7.0.5',
node: '15.1.0',
v8: '8.6.395.17-node.16',
uv: '1.40.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.16.1',
modules: '88',
nghttp2: '1.41.0',
napi: '7',
llhttp: '2.1.3',
openssl: '1.1.1h',
cldr: '37.0',
icu: '67.1',
tz: '2019c',
unicode: '13.0'
}

will@willdesk /home/will/drive/sync/mine/important 20201114.222639
❯❯❯

`

will@willdesk /home/will/drive/sync/mine/important 20201114.222820
❯❯❯uname -a
Linux willdesk 5.9.6-arch1-1 #1 SMP PREEMPT Thu, 05 Nov 2020 21:00:46 +0000 x86_64 GNU/Linux

will@willdesk /home/will/drive/sync/mine/important 20201114.222827
❯❯❯ `

@GaelicGrime
Copy link

updated info

again unsure it is related, I switched from the Arch community package, to the aur/atom-editor-bin package to fix some other issues with the atom editor, now everything works as intended in atom, as well as from the command line, my npm command line has not given me any grief ever, only the apm generated npm error referenced previously

apm no longer generates the npm error on entering any parameters, and atom/apm seem to be using their internal npm, nodejs, etc.

will@willdesk /wsource/python/masherII_DEV 20201122.194216
❯❯❯npm version DEV
{
npm: '7.0.5',
node: '15.2.0',
v8: '8.6.395.17-node.17',
uv: '1.40.0',
zlib: '1.2.11',
brotli: '1.0.9',
ares: '1.16.1',
modules: '88',
nghttp2: '1.41.0',
napi: '7',
llhttp: '2.1.3',
openssl: '1.1.1h',
cldr: '37.0',
icu: '67.1',
tz: '2019c',
unicode: '13.0'
}

will@willdesk /wsource/python/masherII_DEV 20201122.194221
❯❯❯ apm -v DEV
apm 2.5.2
npm 6.14.8
node 12.4.0 x64
atom 1.53.0
python 3.8.6
git 2.29.2

skadefro added a commit to skadefro/openflow that referenced this issue Jan 19, 2021
@joe-gre
Copy link

joe-gre commented Feb 4, 2021

This is caused by an API change in NPM CLI. npm.load now only accepts a callback in the latest version. I'm not sure why this API change was made. This change wasn't present in npm version 6.14.11, it was introduced shortly after that version.

Commit with the change

@ljharb
Copy link
Contributor

ljharb commented Feb 4, 2021

the npm programmatic API hasn’t followed semver since like v3 or something; generally it’d best to shell out to the cli instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 6.x work is associated with a specific npm 6 release
Projects
None yet
Development

No branches or pull requests

5 participants