{"id":15687,"library":"lionel-commonjs-bundler","title":"Lionel CommonJS Bundler","description":"Lionel CommonJS Bundler is a lightweight JavaScript module bundler designed to transform CommonJS modules into a single, browser-compatible JavaScript file. It is currently at version 1.1.1, with its last update approximately three years ago, suggesting a maintenance rather than actively developed phase. The bundler prioritizes simplicity and ease of use, offering minimal configuration options, which differentiates it from more complex tools like Webpack or Rollup. Its primary runtime dependency is `uglify-js` for minification. The bundler is notably used by the Lionel App by default. It supports bundling both directly from code content and from specified file paths.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","commonjs","bundler"],"install":[{"cmd":"npm install lionel-commonjs-bundler","lang":"bash","label":"npm"},{"cmd":"yarn add lionel-commonjs-bundler","lang":"bash","label":"yarn"},{"cmd":"pnpm add lionel-commonjs-bundler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for JavaScript minification during the bundling process.","package":"uglify-js","optional":false},{"reason":"Likely used for command-line interface parsing, though not explicitly shown in quickstart.","package":"commander","optional":false},{"reason":"Provides extended file system functionalities for reading and writing files.","package":"fs-extra","optional":false}],"imports":[{"note":"The library is exclusively CommonJS. Direct ESM `import` statements are not supported. The entry point is specifically `/index`.","wrong":"import { commonJSBundler } from 'lionel-commonjs-bundler'; // ESM import will not work, also incorrect path","symbol":"commonJSBundler","correct":"const { commonJSBundler } = require('lionel-commonjs-bundler/index');"},{"note":"Access `makeCode` as a method of the named export `commonJSBundler`.","wrong":"const bundle = require('lionel-commonjs-bundler').makeCode(content, dir); // May lead to undefined if `commonJSBundler` isn't the direct default export.","symbol":"makeCode","correct":"const { commonJSBundler } = require('lionel-commonjs-bundler/index');\nconst bundle = commonJSBundler.makeCode(content, dir);"},{"note":"Like `makeCode`, `makeFile` is a method accessed via the `commonJSBundler` named export.","wrong":"import { makeFile } from 'lionel-commonjs-bundler/index'; // ESM import will not work.","symbol":"makeFile","correct":"const { commonJSBundler } = require('lionel-commonjs-bundler/index');\nconst bundle = commonJSBundler.makeFile(filePath, dir);"}],"quickstart":{"code":"const { commonJSBundler } = require('lionel-commonjs-bundler/index');\nconst path = require('path');\n\nconst contentOfFile = `\n  const dep = require('./dependency');\n  module.exports = 'Hello ' + dep;\n`;\n\nconst dependencyContent = `\n  module.exports = 'World';\n`;\n\n// Create dummy files for demonstration\nconst fs = require('fs');\nconst tempDir = path.join(__dirname, 'temp_bundler_test');\nif (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir);\nfs.writeFileSync(path.join(tempDir, 'main.js'), contentOfFile);\nfs.writeFileSync(path.join(tempDir, 'dependency.js'), dependencyContent);\n\ntry {\n  const bundle = commonJSBundler.makeFile(path.join(tempDir, 'main.js'), tempDir);\n  console.log('Successfully bundled code:\\n', bundle);\n  // Expected output (minified): 'var dep=require(\"./dependency\");module.exports=\"Hello \"+dep;' (after resolution)\n} catch (error) {\n  console.error('Bundling failed:', error);\n} finally {\n  // Clean up dummy files\n  fs.unlinkSync(path.join(tempDir, 'main.js'));\n  fs.unlinkSync(path.join(tempDir, 'dependency.js'));\n  fs.rmdirSync(tempDir);\n}\n","lang":"javascript","description":"Demonstrates how to use `makeFile` to bundle a CommonJS JavaScript file along with its local dependencies into a single browser-compatible string."},"warnings":[{"fix":"Evaluate alternatives like Webpack, Rollup, or Esbuild for projects requiring active maintenance, modern features, or broader ecosystem compatibility.","message":"The package has not been updated in approximately three years. This may mean it lacks support for newer JavaScript language features (ESM, top-level await, etc.) or security patches for its dependencies, which could be critical for production use.","severity":"gotcha","affected_versions":"<=1.1.1"},{"fix":"Ensure all input source code uses CommonJS `require()` and `module.exports` syntax. For projects requiring ESM, consider alternative bundlers that explicitly support it.","message":"This bundler is specifically designed for CommonJS modules. It does not support ES Modules (ESM) syntax (`import`/`export`) as input. Attempting to bundle ESM will likely result in parsing errors or incorrect output.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For projects with complex needs, consider bundlers like Webpack, Rollup, or Parcel that offer extensive configuration and plugin capabilities. Understand the limitations before committing to this bundler.","message":"The bundler emphasizes simplicity with 'not much configuration options'. This lack of advanced configuration (e.g., extensive plugin ecosystem, granular optimization, tree-shaking) might limit its applicability for complex bundling scenarios or custom requirements found in larger applications.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects, strongly consider using bundlers and module systems (ESM) that align with current JavaScript ecosystem trends to ensure future compatibility and access to modern features.","message":"While CommonJS itself is not deprecated in Node.js, the shift towards ES Modules is significant, with tools and libraries increasingly adopting ESM. Using a bundler exclusively for CJS might lead to interoperability issues with newer dependencies.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are calling methods on the `commonJSBundler` object, e.g., `commonJSBundler.makeCode(content, dir)`.","cause":"Attempting to call `commonJSBundler()` directly as a function, instead of accessing its methods like `makeCode` or `makeFile`.","error":"TypeError: commonJSBundler is not a function"},{"fix":"Use the exact CommonJS `require` path as specified: `require('lionel-commonjs-bundler/index')`. If using `import`, it will not work as this package is CJS-only.","cause":"Incorrect import path or failure to specify the `index` entry point for the CommonJS module. Or, trying to use ESM `import` with a CJS-only package.","error":"Error: Cannot find module 'lionel-commonjs-bundler'"},{"fix":"Check the permissions of the directory where the output file is being written. Run your script with appropriate permissions or choose an output path in a user-writable directory.","cause":"The Node.js process does not have sufficient write permissions to create or modify the output file at the specified path.","error":"Error: EACCES: permission denied, open 'output.js'"}],"ecosystem":"npm"}