{"id":18862,"library":"tokamak","title":"Tokamak","description":"Tokamak is an isomorphic self-bundling bundler (version 0.0.15) aimed at Node.js and browser environments. It converts all modules to CommonJS (CJS) format, deliberately deviating from the ESM trend. Key differentiators include support for CJS-only npm modules and easier automatic HMR isolation. Drawbacks include lack of ESM circular dependency support and export-by-value semantics (e.g., `export let` modifications are not propagated). The bundler runs a static analysis to build a require graph, then generates a dynamic require function for the browser. Actively maintained with irregular releases.","status":"active","version":"0.0.15","language":"javascript","source_language":"en","source_url":"https://github.com/dmaevsky/tokamak","tags":["javascript","bundler","isomorphic"],"install":[{"cmd":"npm install tokamak","lang":"bash","label":"npm"},{"cmd":"yarn add tokamak","lang":"bash","label":"yarn"},{"cmd":"pnpm add tokamak","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for tokenization and parsing.","package":"conclure","optional":false}],"imports":[{"note":"ESM-only import; package does not provide a CJS entry.","wrong":"const tokamak = require('tokamak')","symbol":"default","correct":"import tokamak from 'tokamak'"},{"note":"Named export for the main bundling function; not available via CJS require.","wrong":"const { bundle } = require('tokamak')","symbol":"bundle","correct":"import { bundle } from 'tokamak'"},{"note":"TypeScript-only type export; do not import at runtime.","wrong":"import { BundleOptions } from 'tokamak' // runtime error","symbol":"type BundleOptions","correct":"import type { BundleOptions } from 'tokamak'"},{"note":"Separate runtime subpath export for browser-side module loading.","wrong":"import { createRuntime } from 'tokamak'","symbol":"createRuntime","correct":"import { createRuntime } from 'tokamak/runtime'"}],"quickstart":{"code":"import { bundle } from 'tokamak';\n\nconst result = await bundle({\n  entry: './src/index.js',\n  format: 'cjs',\n  outDir: './dist',\n  minify: true,\n  sourceMap: true,\n  target: 'es2015',\n  external: ['lodash'],\n});\n\nconsole.log('Output files:', result.files);\nconsole.log('Metadata:', result.meta);","lang":"typescript","description":"Shows the bundle function being called with common options like entry, outDir, minify, and sourceMap."},"warnings":[{"fix":"Refactor circular dependencies to use CJS-compatible patterns or avoid cycles.","message":"ESM circular dependencies are not supported and will cause runtime errors.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Use object-style exports (e.g., export const obj = { foo: 'bar' }) if mutation is needed.","message":"Exports are by value: `export let foo = 'bar'` cannot be mutated by other modules.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Upgrade Node.js to >=14.17.0.","message":"Only Node.js >=14.17.0 is supported; earlier versions will fail.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Replace `preserveModules: true` with `outDir: './dist'`.","message":"The `preserveModules` option has been deprecated in favor of `outDir` since version 0.0.12.","severity":"deprecated","affected_versions":">=0.0.12"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install the missing module as a dependency or remove it from the `external` array.","cause":"Missing external module resolution when `external` option includes a module not installed.","error":"TypeError: Cannot read properties of undefined (reading 'resolve')"},{"fix":"Ensure all babel transforms are disabled or use Tokamak's default transform pipeline by not providing custom babel config.","cause":"Using an incompatible babel plugin or preset (e.g., @babel/preset-env) that conflicts with Tokamak's internal parser.","error":"Error: [BABEL] unknown: You gave us a visitor for the node type \"ExportDefaultDeclaration\" but it's not a valid type"},{"fix":"Either install the dependency or add it to the `external` array and ensure it's available at runtime.","cause":"Missing external dependency that is not marked in `external` but is not bundled (e.g., due to incorrect resolution).","error":"Module not found: Error: Can't resolve 'lodash' in '/path/to/project'"},{"fix":"Set `target` to a suitable ECMAScript version (e.g., 'es2015') or ensure the input files are already in CJS format.","cause":"Input file uses ESM syntax (e.g., export) but the bundler is configured to output CJS without proper transpilation.","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}