babel-preset-liferay-standard
raw JSON → 2.32.2 verified Sat Apr 25 auth: no javascript
A Babel preset for bundling standard (browser-compatible) npm modules in Liferay projects. Current stable version is 2.32.2. It is maintained as part of the Liferay frontend projects monorepo, with releases tied to the liferay-js-toolkit package. The preset includes plugins for normalizing requires, inlining NODE_ENV, dead code elimination, AMD module wrapping, naming, and namespace handling. It differentiates from generic Babel presets by providing Liferay-specific transformations for AMD module support and namespace isolation.
Common errors
error Error: Cannot find module 'babel-preset-liferay-standard' ↓
cause Package not installed or missing from devDependencies.
fix
Run: npm install --save-dev babel-preset-liferay-standard
error ReferenceError: define is not defined ↓
cause AMD module wrapping expects an AMD loader (e.g., RequireJS) to be present in the browser.
fix
Ensure an AMD loader (like RequireJS) is included or use the preset with a bundler that supports AMD output.
error TypeError: Cannot read property 'presets' of undefined ↓
cause Babel configuration file is malformed or missing module.exports.
fix
Export an object with a presets array: module.exports = { presets: ['liferay-standard'] };
error Error: Plugin 2 specified in ".../node_modules/babel-preset-liferay-standard/index.js" returned an object with a "visitor" property, but Babel expects a function. ↓
cause Incompatible Babel plugin version (e.g., Babel 6 plugin in Babel 7).
fix
Upgrade to Babel 7 or ensure all peer dependencies match.
Warnings
breaking In version 2.x, the preset requires Babel 7. Using with Babel 6 will throw errors. ↓
fix Upgrade to Babel 7 or use babel-preset-liferay-standard@1.x.
deprecated babel-plugin-transform-node-env-inline may be deprecated in future releases; prefer using @babel/plugin-transform-node-env-inline. ↓
fix Manually replace with the standalone plugin if needed.
gotcha The preset includes dead code elimination; ensure that process.env.NODE_ENV is set correctly to avoid accidental removal of development code. ↓
fix Set NODE_ENV=production for production builds or use cross-env.
gotcha AMD module wrapping can cause conflicts with other module systems (e.g., CommonJS). Ensure your project is AMD-compatible. ↓
fix Use the preset only in Liferay AMD environments or disable AMD plugins if not needed.
Install
npm install babel-preset-liferay-standard yarn add babel-preset-liferay-standard pnpm add babel-preset-liferay-standard Imports
- default wrong
const babelPresetLiferayStandard = require('babel-preset-liferay-standard')correctimport babelPresetLiferayStandard from 'babel-preset-liferay-standard' - liferayStandard wrong
import { LiferayStandard } from 'babel-preset-liferay-standard'correctimport { liferayStandard } from 'babel-preset-liferay-standard' - Config wrong
import { Config } from 'babel-preset-liferay-standard'correctimport type { Config } from 'babel-preset-liferay-standard'
Quickstart
// Install: npm install --save-dev babel-preset-liferay-standard
// .babelrc
{
"presets": ["liferay-standard"]
}
// babel.config.js
module.exports = {
presets: ['babel-preset-liferay-standard']
};
// package.json
{
"babel": {
"presets": ["liferay-standard"]
}
}