{"id":14435,"library":"asbundle","title":"asbundle: Minimalistic CommonJS Bundler","description":"asbundle (current stable version 2.7.0) is a focused JavaScript bundler designed to convert single ES Module or CommonJS source files into a lightweight, optimized CommonJS bundle, primarily for browser environments. It serves as a companion to `ascjs` and utilizes `babylon` for parsing, automatically transforming ES2015+ modules into CommonJS when necessary. Its core differentiators include its minimalistic design, aiming for simplicity over feature breadth, and its ability to produce small, minifier-friendly bundles that do not rely on a global `require` or runtime dependency resolution. It prioritizes compatibility with downstream tools like Babel and UglifyJS, supports both relative file paths and `node_modules` package resolution, and reproduces a modern CommonJS environment ideal for web browsers. It explicitly avoids replacing comprehensive bundlers like Webpack or Rollup, focusing solely on `import`/`export` transpilation. The package was last published 5 years ago, suggesting a maintenance or stable status with infrequent updates.","status":"maintenance","version":"2.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/WebReflection/asbundle","tags":["javascript","esm","cjs","commonjs","browserify","alternative","bundler","simple","basic"],"install":[{"cmd":"npm install asbundle","lang":"bash","label":"npm"},{"cmd":"yarn add asbundle","lang":"bash","label":"yarn"},{"cmd":"pnpm add asbundle","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to automatically transform ES2015+ modules into CommonJS code for bundling.","package":"ascjs","optional":false},{"reason":"Used for performance and reliability in parsing JavaScript code.","package":"babylon","optional":false}],"imports":[{"note":"asbundle itself is distributed as a CommonJS module, so direct ES Module `import` syntax will result in a runtime error. Use `require` for programmatic access.","wrong":"import asbundle from 'asbundle';","symbol":"asbundle","correct":"const asbundle = require('asbundle');"}],"quickstart":{"code":"const asbundle = require('asbundle');\nconst fs = require('fs');\nconst path = require('path');\n\n// Create dummy source files for the example to be runnable\nconst tempDir = path.join(__dirname, 'temp_asbundle_example');\nfs.mkdirSync(tempDir, { recursive: true });\n\nfs.writeFileSync(path.join(tempDir, 'main.js'), `\nimport func, {a, b} from './module.js';\nconst val = 123;\nexport default function test() {\n  console.log('asbundle');\n};\nexport {func, val};\n    `);\nfs.writeFileSync(path.join(tempDir, 'module.js'), `\nexport const a = 1, b = 2;\nexport default function () {\n  console.log('module');\n};\n    `);\n\nasync function bundleExample() {\n  try {\n    const sourceFileName = path.join(tempDir, 'main.js');\n    const bundleContent = await asbundle(sourceFileName);\n\n    console.log('Generated bundle content:\\n');\n    console.log(bundleContent);\n\n    // Clean up temporary files\n    fs.unlinkSync(path.join(tempDir, 'main.js'));\n    fs.unlinkSync(path.join(tempDir, 'module.js'));\n    fs.rmdirSync(tempDir);\n    console.log('\\nTemporary files cleaned up.');\n\n  } catch (error) {\n    console.error('Bundling failed:', error.message);\n    // Ensure cleanup even on error\n    if (fs.existsSync(path.join(tempDir, 'main.js'))) fs.unlinkSync(path.join(tempDir, 'main.js'));\n    if (fs.existsSync(path.join(tempDir, 'module.js'))) fs.unlinkSync(path.join(tempDir, 'module.js'));\n    if (fs.existsSync(tempDir)) fs.rmdirSync(tempDir);\n  }\n}\n\nbundleExample();","lang":"javascript","description":"Demonstrates programmatic usage of `asbundle` to transform an ES Module entry point (`main.js`) and its dependency (`module.js`) into a single CommonJS compatible string, then logs the result."},"warnings":[{"fix":"Refactor code to avoid Node.js core modules in browser bundles or use browser-compatible alternatives/shims for those functionalities.","message":"Node.js core modules (e.g., `fs`, `path`, `http`) are not bundled by `asbundle`. If your source code requires these modules and the bundle is intended for a browser environment, `asbundle` will throw an error if it cannot resolve them as local files or installed packages.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure all `require` statements use static string literals for module paths. Avoid any form of dynamic module loading that `asbundle` cannot resolve at build time.","message":"`asbundle` inherits constraints from `ascjs`, its underlying transformer. This means dynamic `require` calls (e.g., `require(variable)`) are not supported and will lead to bundling failures or incorrect output. All `require` statements must be statically analyzable.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Maintain a consistent module syntax (either CommonJS or ES Modules) within each source file. Avoid hybrid module patterns where both `module.exports` and `export default` are present.","message":"`ascjs` (and thus `asbundle`) does not fully support mixing CommonJS `module.exports`/`exports.property` syntax with ES Module `export default` in the same file. This can lead to unpredictable behavior or errors during transformation.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure the required package is installed via `npm install <package-name>` or `yarn add <package-name>`. Verify the module path is correct relative to the importing file or resolvable from `node_modules`.","cause":"The module specified in a `require()` or `import` statement could not be resolved. This often indicates a missing `node_modules` dependency or an unresolvable path.","error":"Error: Cannot find module 'some-npm-package' from 'path/to/your-file.js'"},{"fix":"If the bundle is for the browser, remove or replace usage of Node.js core modules with browser-compatible alternatives. If it's a Node.js target, `asbundle` might not be the right tool or you need to ensure the module is externalized.","cause":"A Node.js core module (like `fs`, `path`, `http`) is being required, but `asbundle` does not include these in the browser-targeted bundle. It attempts to resolve them as regular files/packages, which fails.","error":"Error: Cannot find module 'fs' from 'path/to/your-file.js'"}],"ecosystem":"npm"}