babel-plugin-normalize-requires

raw JSON →
2.32.2 verified Sat Apr 25 auth: no javascript

A Babel plugin that normalizes AMD require() calls by removing file extensions (e.g., .js) and trailing slashes from module paths. Version 2.32.2 is current; part of the Liferay Frontend Projects monorepo. It is designed for Liferay's AMD module system and does not handle CommonJS or ES module imports. Key differentiator: it preserves npm package names that contain .js (e.g., a package named 'foo.js') while normalizing module paths. Release cadence is irregular, tied to Liferay SDK updates.

error require('./a-module.js') not normalized
cause The require() call is inside a non-AMD context or the plugin is not configured correctly.
fix
Ensure Babel is configured with the plugin in .babelrc and that the code is processed by Babel (check for exclude/include patterns).
error Error: Cannot find module 'babel-plugin-normalize-requires'
cause Package not installed or missing from node_modules.
fix
Run 'npm install --save-dev babel-plugin-normalize-requires' and verify package.json.
breaking Plugin only processes AMD define()/require() calls, not CommonJS require() or ES import statements.
fix Use with Babel preset-env or other plugins if targeting CJS/ESM: the plugin will silently skip non-AMD calls.
gotcha The plugin does not handle dynamic require() calls (e.g., require(variable)).
fix Ensure require() arguments are string literals for normalization to occur.
deprecated Package may not be actively maintained as part of Liferay Frontend Projects; no recent releases for this package specifically.
fix Consider forking or migrating to alternative module normalization tools if updates are needed.
npm install babel-plugin-normalize-requires
yarn add babel-plugin-normalize-requires
pnpm add babel-plugin-normalize-requires

Configures Babel to strip .js suffixes and trailing slashes from AMD require() calls.

// .babelrc
{
  "plugins": ["normalize-requires"]
}

// Input: require('./a-module.js');
// Output: require('./a-module');