ChemInfo Build Tool
cheminfo-build is a specialized Command Line Interface (CLI) tool designed to streamline the build process for packages within the ChemInfo ecosystem. It automates common tasks such as bundling JavaScript for various environments (ESM, UMD), generating source maps, and creating minified versions. The package is currently at version 1.3.2 and receives regular updates, primarily for dependency management and minor fixes, with major breaking changes occurring less frequently. For example, v1.3.0 introduced significant changes to module resolution and bundle extensions. Its key differentiators include its focus on ChemInfo package conventions and its ability to handle modern JavaScript module formats (ESM, CJS) with configurable output paths and naming conventions.
Common errors
-
Error: Cannot find module 'cheminfo-build' or 'cheminfo-build/dist/my-package.js'
cause This error often occurs when attempting programmatic import of the package when it's not correctly installed, or when using an incorrect/deprecated path for a specific bundle file. This is especially relevant after v1.3.0's changes to bundle extensions (.umd.cjs, .esm.mjs) and export precedence.fixEnsure `cheminfo-build` is installed as a dependency (`npm install cheminfo-build` or `npm install -D cheminfo-build`). For programmatic use, rely on standard module imports like `import { build } from 'cheminfo-build'` or `const { build } = require('cheminfo-build')`, which correctly utilize `package.json`'s `exports` field for resolution, rather than hardcoding paths to `dist` files. -
cheminfo-build: command not found
cause The `cheminfo-build` executable is not accessible in the system's PATH. This typically happens when the package is installed as a local `devDependency` and the command is not invoked from within the local `node_modules/.bin` directory or via `npx`.fixExecute the command using `npx cheminfo-build <options>` to leverage the locally installed version from your project's `node_modules`. Alternatively, ensure `node_modules/.bin` is included in your system's PATH, or call the executable directly from `node_modules/.bin/cheminfo-build`.
Warnings
- breaking Starting with version 1.3.0, `cheminfo-build` introduced significant breaking changes to its module resolution and bundle output conventions. It now prioritizes the `exports` field in `package.json` for determining module entry points, aligning with modern Node.js practices. Furthermore, UMD bundles are renamed to `.umd.cjs`, and new ESM bundles are generated with the `.esm.mjs` extension.
- gotcha `cheminfo-build` frequently updates its internal dependencies, as indicated by recent releases. While typically non-breaking, these updates can sometimes introduce subtle changes, compatibility issues with older Node.js versions, or conflicts with other project dependencies if not regularly managed.
Install
-
npm install cheminfo-build -
yarn add cheminfo-build -
pnpm add cheminfo-build
Imports
- build
import cheminfoBuild from 'cheminfo-build'; // Incorrect if 'build' is a named export.
import { build } from 'cheminfo-build'; - build
const build = require('cheminfo-build'); // Incorrect if 'build' is a named export, common error.const { build } = require('cheminfo-build'); - CLI Usage
npx cheminfo-build <options>
Quickstart
npm install -D cheminfo-build
// Example package.json with a custom build script
// This demonstrates how to integrate cheminfo-build into a typical project workflow.
// {
// "name": "my-cheminfo-package",
// "version": "1.0.0",
// "main": "dist/my-cheminfo-package.umd.cjs",
// "module": "dist/my-cheminfo-package.esm.mjs",
// "exports": {
// ".": {
// "import": "./dist/my-cheminfo-package.esm.mjs",
// "require": "./dist/my-cheminfo-package.umd.cjs"
// }
// },
// "scripts": {
// "build": "cheminfo-build -e src/index.js -o dist -n my-cheminfo-package --no-source-map"
// }
// }
// To execute the build command defined in package.json:
// In your terminal:
// npm run build
// Or, for direct CLI execution without a package.json script:
// npx cheminfo-build -e src/index.js -o dist -n my-cheminfo-package --no-minify