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

TypeError: ncu is not a function #1199

Closed
1 task done
atomicrobokid opened this issue Sep 29, 2022 · 2 comments
Closed
1 task done

TypeError: ncu is not a function #1199

atomicrobokid opened this issue Sep 29, 2022 · 2 comments
Labels

Comments

@atomicrobokid
Copy link

atomicrobokid commented Sep 29, 2022

  • I have searched for similar issues
  • [x ] I am using the latest version of npm-check-updates
  • [x ] I am using node >= 14

Steps to Reproduce

import ncu from 'npm-check-updates'

export const upgrades = await ncu({
    // Pass any cli option
    packageFile: './package.json',
    upgrade: false,
    interactive: false,
    filter: 'npm-check-updates'
})

console.log(upgrades)

Steps:

New project using "npm-check-updates": "16.3.0",

Use recommended config, run node foo.js

Current Behavior

Following the README, I have set up a basic js file with the config above. When i run that I get

export const upgrades = await ncu({
                              ^

TypeError: ncu is not a function

I am used Node v16.17.0 and npm 8.15.0. Tried adding and removing "type": "module" from my package.json. Tried in both vanilla js and compiling with tsc.

Expected Behavior

Expected to successfully log

@raineorshine
Copy link
Owner

raineorshine commented Sep 29, 2022

Hi, thanks for reporting.

I'm not quite sure what the issue is, as npm-check-updates exports a function run as the default export:

export default run

However, it is also exported as a named function, so you can try ncu.run(...) or import { run } from 'npm-check-updates'.

export async function run(
runOptions: RunOptions = {},
{ cli }: { cli?: boolean } = {},
): Promise<PackageFile | Index<VersionSpec> | void> {

Here is a sample Typescript repo that compiles correctly with the documented usage:

https://github.com/raineorshine/ncu-test-import-as-module/blob/main/src/index.ts

It basically just consists of:

import ncu from 'npm-check-updates'

const upgrades = await ncu()
console.log(upgrades)

If that doesn't work , try import * as ncu from 'npm-check-updates'. Maybe the method of importing is different if using node v16 without Typescript.

@atomicrobokid
Copy link
Author

atomicrobokid commented Sep 30, 2022

@raineorshine

Ahh that was the trick, thanks! This is what I needed in the end:

import * as ncu from 'npm-check-updates'

const upgrades = await ncu.run()
console.log(upgrades)

Thanks for your help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants