{"id":13437,"library":"libnpmfund","title":"libnpmfund: npm Fund Programmatic API","description":"The `libnpmfund` package offers a dedicated programmatic API for interfacing with the `npm fund` command, enabling developers to integrate dependency funding information retrieval directly into their applications. As per the provided metadata, its current stable version is 7.0.19. This package is an integral component of the broader npm CLI ecosystem, undergoing regular maintenance and receiving updates in alignment with new npm CLI releases, which implies an active and responsive development cycle. Its primary advantage lies in providing a structured, JavaScript-native interface to access the aggregated funding data, which is typically presented by the `npm fund` CLI. This capability is crucial for building automated tools, dashboards, or custom reporting systems that need to analyze or display dependency funding without relying on external process execution or parsing CLI output. It explicitly depends on `@npmcli/arborist` for robust dependency graph traversal and analysis.","status":"active","version":"7.0.19","language":"javascript","source_language":"en","source_url":"https://github.com/npm/cli","tags":["javascript","npm","npmcli","libnpm","cli","git","fund","gitfund"],"install":[{"cmd":"npm install libnpmfund","lang":"bash","label":"npm"},{"cmd":"yarn add libnpmfund","lang":"bash","label":"yarn"},{"cmd":"pnpm add libnpmfund","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for traversing and analyzing the dependency tree to identify funding sources.","package":"@npmcli/arborist","optional":false}],"imports":[{"note":"The primary function to retrieve funding information. Uses ESM by default due to modern Node.js engine requirements. Avoid direct CommonJS require if your environment is ESM-first.","wrong":"const fund = require('libnpmfund')","symbol":"fund","correct":"import { fund } from 'libnpmfund'"},{"note":"Type import for configuration options passed to the `fund` function, enabling type-safe usage in TypeScript projects.","symbol":"FundOptions","correct":"import type { FundOptions } from 'libnpmfund'"},{"note":"Type import for the structured result object returned by the `fund` function, providing strong typing for the funding data.","symbol":"FundResult","correct":"import type { FundResult } from 'libnpmfund'"}],"quickstart":{"code":"import { fund } from 'libnpmfund';\nimport path from 'path';\n\nasync function getFundingInfo(projectPath: string) {\n  try {\n    console.log(`Attempting to retrieve funding information for: ${projectPath}`);\n    // The `fund` function typically needs a path and an options object.\n    // Setting `json: true` is crucial for programmatic consumption to get structured data.\n    const result = await fund(projectPath, {\n      json: true, \n      // Other options can be passed, e.g., to only include production dependencies:\n      // production: true,\n      // or for a specific workspace:\n      // workspace: 'my-workspace-name'\n    });\n\n    if (result && Object.keys(result).length > 0) {\n      console.log('Successfully retrieved funding information:');\n      // Log the result with full depth to see the entire structure\n      console.dir(result, { depth: null, colors: true });\n    } else {\n      console.log('No funding information found for this project or its dependencies.');\n    }\n    return result;\n  } catch (error) {\n    console.error(`Failed to get funding info for ${projectPath}:`, error);\n    throw error; // Re-throw to propagate the error\n  }\n}\n\n// Example usage: Get funding for the current project directory where the script is run\nconst currentProjectPath = path.resolve('.');\ngetFundingInfo(currentProjectPath)\n  .then(() => console.log('\\nFunding info retrieval process complete.'))\n  .catch(err => console.error('\\nAn unhandled error occurred during quickstart execution:', err));","lang":"typescript","description":"This quickstart demonstrates how to programmatically retrieve funding information for a JavaScript/TypeScript project's dependencies using `libnpmfund`. It calls the `fund` function with the current project path and requests JSON output, then logs the structured funding data to the console, providing an insight into how maintainers can be supported programmatically."},"warnings":[{"fix":"Review the official npm CLI GitHub repository release notes or `libnpmfund`'s changelog for specific breaking changes. Adapt your code to the new API as documented.","message":"Major version updates for `libnpmfund` (e.g., from v6 to v7) typically introduce breaking changes in API signatures, available options, or the structure of returned data. Always consult the official release notes when upgrading.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Ensure your Node.js environment meets the specified engine requirements. Update Node.js to a compatible version using a version manager like `nvm` or `volta`.","message":"The package has strict Node.js engine requirements (`^20.17.0 || >=22.9.0`). Using an older Node.js version than specified in the `engines` field will result in runtime errors.","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"When debugging issues related to dependency resolution or tree traversal with `libnpmfund`, consider checking the `@npmcli/arborist` package's release notes for relevant changes, known issues, or potential workarounds.","message":"As a component of the `npm/cli` ecosystem, `libnpmfund` heavily relies on `@npmcli/arborist` for core dependency tree resolution logic. Updates or changes in Arborist's behavior can indirectly impact `libnpmfund`'s functionality, performance, or output.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Migrate your import statements to use ESM syntax: `import { fund } from 'libnpmfund';`. If your project must remain CommonJS, consider using dynamic import `await import('libnpmfund')`.","cause":"`libnpmfund` is primarily distributed as an ES Module (ESM). Attempting to import it using CommonJS `require()` syntax directly will result in this error in modern Node.js environments.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/libnpmfund/index.js from ... is not supported."},{"fix":"Verify your import statement: `import { fund } from 'libnpmfund';`. Ensure `libnpmfund` is correctly installed via `npm install libnpmfund` and try deleting `node_modules` and `package-lock.json` before reinstalling if issues persist.","cause":"This error typically indicates that the `fund` export was not correctly imported, or the module itself failed to load. This can happen due to incorrect import paths, a corrupted `node_modules` installation, or a typo in the symbol name.","error":"TypeError: fund is not a function"},{"fix":"Ensure that the first argument passed to `fund()` is a string representing the absolute or relative path to the project directory you wish to analyze. For example, `fund(path.resolve('./my-project'))` or `fund('.')`.","cause":"The `fund` function requires a valid project path (a string) as its first argument. Passing `undefined`, `null`, or any non-string value will trigger this type error.","error":"TypeError: The \"path\" argument must be of type string. Received undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}