ycp-rollup-starter-lib
raw JSON → 1.0.16 verified Mon Apr 27 auth: no javascript
A bare-bones example repository demonstrating how to create a JavaScript library using Rollup, including importing a CommonJS module from node_modules. The library 'how-long-till-lunch' uses the 'ms' package to calculate time until lunch. This is a starter template, not a standalone library; version 1.0.16 is active but has no maintainer activity. Key differentiators: it provides CommonJS, ES module, and UMD builds via Rollup, with variations for Babel or Bublé transpilation. Not intended for production use as a dependency.
Common errors
error Error: Cannot find module 'ms' ↓
cause The 'ms' package is installed as a devDependency but your code uses it at runtime. Running the built library outside the project directory fails.
fix
Run npm install --save ms to add it as a runtime dependency, or ensure you run your application from within the project directory.
error npm ERR! code ELIFECYCLE ↓
cause Build script fails due to missing rollup or other dev dependencies.
fix
Run npm install before npm run build.
error SyntaxError: Unexpected token 'export' ↓
cause Trying to run the ES module file directly with older Node.js versions (<13) without ESM support.
fix
Use Node.js version 13 or later with --experimental-modules flag, or use the CommonJS bundle instead.
Warnings
gotcha This package is a starter template, not a published library. Do not install it as a dependency (npm install ycp-rollup-starter-lib) expecting a usable library. ↓
fix Clone the GitHub repo instead: git clone https://github.com/rollup/rollup-starter-lib.git
deprecated The Greenkeeper badge is outdated. Greenkeeper was acquired by Snyk and the service changed. ↓
fix Consider using Dependabot or Renovate for dependency updates.
gotcha The 'ms' dependency is a devDependency in the starter, but the example imports it as if it were a runtime dependency. This may confuse beginners. ↓
fix If you use the starter as a base for your own library, move 'ms' to dependencies if your library uses it at runtime.
Install
npm install ycp-rollup-starter-lib yarn add ycp-rollup-starter-lib pnpm add ycp-rollup-starter-lib Imports
- default
import howLongTillLunch from './how-long-till-lunch'; - require wrong
const howLongTillLunch = require('how-long-till-lunch');correctconst howLongTillLunch = require('./how-long-till-lunch.cjs.js'); - script tag
<script src="dist/how-long-till-lunch.umd.js"></script>
Quickstart
// Clone and build the library
git clone https://github.com/rollup/rollup-starter-lib.git
cd rollup-starter-lib
npm install
npm run build
// Create a test file: test.mjs
import howLongTillLunch from './dist/how-long-till-lunch.esm.js';
console.log('Lunch in:', howLongTillLunch());
// Run with node
node test.mjs