Registry / web-framework / unpkg-bundler

unpkg-bundler

JSON →
library0.0.12jsnpmunverified

unpkg-bundler is a client-side JavaScript library (current version 0.0.12) designed for in-browser code transpilation and bundling, with a unique capability to dynamically fetch and load npm packages directly from unpkg.com. It leverages esbuild internally for high-performance bundling and supports both ES modules (ESM) and CommonJS (CJS) syntax, as well as TypeScript and TSX with React code. The library's core differentiator is its ability to operate without filesystem access, making it ideal for browser-based development environments, interactive code editors, or learning platforms that need to execute user-provided code with npm dependencies on the fly. Its release cadence is currently irregular, typical for projects in early development.

npm install unpkg-bundler
INSTALL
IMPORT
SIG · UNPKG-BUNDLER
U
unpkg-bundler
web-frameworkjavascriptv0.0.12
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

bundle
import bundle from 'unpkg-bundler';
import { bundle } from 'unpkg-bundler'; const bundle = require('unpkg-bundler');
The main `bundle` function is a default export. For CommonJS environments, explicitly import from `unpkg-bundler/lib/cjs`. The primary package entry point is ESM.

Demonstrates bundling a React component, including automatic fetching of `react` and `react-dom` from `unpkg.com`, and shows how to execute the resulting bundled code in a browser environment.

import bundle from 'unpkg-bundler'; // React component code to be bundled. // unpkg-bundler will automatically fetch React and ReactDOM from unpkg. const reactCode = ` import React from 'react'; import ReactDOM from 'react-dom'; const App = () => { return ( <div style={{ fontFamily: 'sans-serif', textAlign: 'center' }}> <h1>Hello from unpkg-bundler!</h1> <h2>This code was bundled and transpiled on the client-side.</h2> <p>It automatically fetched React and ReactDOM from unpkg.com.</p> </div> ); }; // Typically, you'd render this into an existing DOM element. // For this quickstart, we'll just demonstrate the bundling output. const rootElement = document.createElement('div'); rootElement.id = 'root'; document.body.appendChild(rootElement); ReactDOM.render(<App />, rootElement); `; const runBundle = async () => { console.log('Bundling React code...'); const { code, err } = await bundle(reactCode); if (err) { console.error('Bundling error:', err); return; } console.log('Bundle successful. Executing code...'); // To execute in a browser, you can create a <script> tag or use eval. // Be cautious with eval in production due to security implications. // For demonstration: try { // This will execute the bundled code directly in the current scope. // In a real application, you might inject it into an iframe for isolation. new Function(code)(); console.log('Code executed successfully. Check the document body for the React app.'); } catch (executionError) { console.error('Error executing bundled code:', executionError); } }; runBundle();
Debug
Known issues
gotchaThe package is in early development (v0.0.12) and APIs might change frequently without following strict semantic versioning practices.
fix
Review release notes carefully for updates and consider pinning exact versions in production environments to avoid unexpected changes.
affects: >=0.0.1
gotchaThe `bundle` function is asynchronous and must be awaited within an `async` context to correctly retrieve results. Forgetting `await` will result in a Promise object instead of the bundled code.
fix
Ensure calls to `bundle()` are prefixed with `await` and are contained within an `async` function or a top-level `await` context.
affects: >=0.0.1
gotcha`unpkg-bundler` is designed for client-side use without filesystem access. It cannot resolve local file paths or perform operations requiring Node.js-specific modules (like `fs`).
fix
Ensure all input code is provided as a string, and dependencies are resolved via `unpkg.com` or are self-contained within the input string.
affects: >=0.0.1
gotchaCommonJS users importing the package via `require()` must specify the CommonJS entry point at `'unpkg-bundler/lib/cjs'`, as the default package entry is an ES module.
fix
Use `const bundle = require('unpkg-bundler/lib/cjs');` for CommonJS environments.
affects: >=0.0.1
gotchaThe `bundle` function is a default export. Attempting to destructure it as a named import (e.g., `import { bundle } from 'unpkg-bundler';`) will result in `undefined` or a runtime error.
fix
Always import `bundle` as a default import: `import bundle from 'unpkg-bundler';`.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: (0 , unpkg_bundler__WEBPACK_IMPORTED_MODULE_0__.bundle) is not a function
Attempting to import `bundle` as a named export when it is a default export in an ESM context (common with bundlers like Webpack/Vite).
fix
Change `import { bundle } from 'unpkg-bundler';` to `import bundle from 'unpkg-bundler';`.
SyntaxError: await is only valid in async functions and the top level bodies of modules
Using `await bundle(...)` outside of an `async` function or a top-level `await` context.
fix
Wrap the call to `bundle` in an `async` function, e.g., `const createBundle = async () => { const { code, err } = await bundle(modules); };`.
ReferenceError: require is not defined
Trying to use CommonJS `require` in an ES module environment (e.g., in a browser or a Node.js module configured as `type: "module"`).
fix
For ESM, use `import bundle from 'unpkg-bundler';`. For CommonJS, use `const bundle = require('unpkg-bundler/lib/cjs');`.
Upgrade
Version history
0.0.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
unpkg-bundler — npm install unpkg-bundler · libregistry