babel-plugin-show-source
raw JSON → 0.2.1 verified Sat Apr 25 auth: no javascript
A Babel plugin that transforms functions to include their source code via Function.prototype.toString() for runtime introspection. Current stable version is 0.2.1 (pre-1.0.0, still experimental). The release cadence is low; last update was 2023. It is a niche tool intended for debugging, serialization, or educational demos where preserving function text is needed. Note the pre-release versioning and possible breaking changes in minor versions.
Common errors
error Error: Cannot find module 'babel-plugin-show-source' ↓
cause Missing dependency; not installed in node_modules.
fix
Run
npm install --save-dev babel-plugin-show-source or yarn add -D babel-plugin-show-source. error TypeError: plugin is not a function ↓
cause Incorrect import; attempting to use default import as a function.
fix
Use
import showSource from 'babel-plugin-show-source' in ESM or ensure proper default import resolution in CommonJS. Warnings
gotcha Plugin may break if Babel options like 'compact' or 'retainLines' are used. ↓
fix Avoid using conflicting options; test with your Babel configuration.
breaking Version 0.2.0 changed the output format; source string may differ in whitespace from original. ↓
fix Check updated output, adjust any string comparisons if needed.
deprecated The 'show-source' option in Babel config is deprecated in favor of direct plugin usage. ↓
fix Use 'plugins' array directly instead of 'env' or 'overrides' options.
Install
npm install babel-plugin-show-source yarn add babel-plugin-show-source pnpm add babel-plugin-show-source Imports
- default wrong
const showSource = require('babel-plugin-show-source');correctimport showSource from 'babel-plugin-show-source'
Quickstart
// babel.config.js
module.exports = {
plugins: [
'babel-plugin-show-source',
// or with options:
// ['babel-plugin-show-source', { /* options */ }]
]
};
// Input file (source.js)
function greet(name) {
return `Hello, ${name}!`;
}
console.log(greet.toString());
// After transformation, greet.toString() returns the full source code
// Output: 'function greet(name) { return `Hello, ${name}!`; }'