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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
babel
✓ const babel = require('babel'); babel.transform(code, { plugins: ['babel-gettext-plugin'] })
✗ import babel from 'babel'; // ESM import not supported; Babel 7's API is CJS
Plugin is used via Babel's transform API; not imported directly. Must be required in CommonJS context.
plugin config
✓ plugins: [['babel-gettext-plugin', { headers: {}, functionNames: {} }]]
✗ plugins: ['babel-gettext-plugin', { headers: {} }] // wrong: array nesting
Options must be passed as the second element of an array, not as separate arguments.
CLI usage
✓ babel --plugins babel-gettext-plugin input.js -o output.js
✗ babel --plugin babel-gettext-plugin code.js // wrong: '--plugin' should be '--plugins'
Use --plugins, not --plugin. Options can be appended with colon, e.g. --plugins babel-gettext-plugin:{"fileName":"test.po"}
Demonstrates plugin setup with Babel 7, custom function names for extraction, and .pot file output.
const babel = require('@babel/core');
const code = `
const _ = require('gettext');
const msg = _('Hello world');
console.log(_('Goodbye', 'context'));
`;
babel.transform(code, {
plugins: [
['babel-gettext-plugin', {
headers: {
'content-type': 'text/plain; charset=UTF-8',
'plural-forms': 'nplurals=2; plural=(n!=1);'
},
functionNames: {
mygettext: ['msgid'],
myngettext: ['msgid', 'msgid_plural', 'count']
},
fileName: './locales/messages.pot',
defaultTranslate: false
}]
]
}).then(result => {
console.log('Extraction complete, check .pot file.');
}).catch(err => console.error(err));
Errors
Common errors & fixes
Error: Cannot find module 'babel'
Incorrect Babel package: babel 6 vs @babel/core 7 naming.
fixUse '@babel/core' instead of 'babel': npm install @babel/core and const babel = require('@babel/core'); TypeError: Cannot read property 'traverse' of undefined
Plugin used with Babel 6 but installed v3.0.0 (requires Babel 7).
fixInstall v2.x: npm install babel-gettext-plugin@2.x --save-dev
Warning: No strings extracted.
Plugin cannot find gettext call syntax (default function name '_'). No custom functionNames set.
fixDefine functionNames matching your gettext wrapper names, e.g., 'mygettext': ['msgid']
Audit
Dependencies
babelrequiredRequires Babel 7 to transform code and apply the plugin
node-gettextrequiredCore library used for gettext parsing and .po file generation