![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
babel-plugin-root-require
Advanced tools
Transforms require module paths that have a prefix referring to the project root. Also works on `require.resolve`.
Transforms require module paths that have a prefix referring to the project root. Also works on require.resolve
.
npm install babel-plugin-root-require
// these paths will work from any file in the project root (src)
require('~/foo/a')
require('~/bar/b')
require('~/bar/baz/c')
require('~/d')
// foo/a.js
require('~/d') // -> require('../d')
{
"plugins": [
["root-require", {
"projectRoot": "src"
}]
]
}
babel src --out-dir build
Prefix that refers to the project root
Absolute path of project root or relative path from process.cwd() to the project root which prefix
refers to. Module paths will not be resolved correctly if this option is not correct. In the typical case that the source code is under the src
directory, but babel is executed in the parent directory of src
, set projectRoot: src
.
By default, transformed module paths will be the most efficient path from the requiring file to the module. When long
is true
, the prefix will be transformed to the relative path up the tree to the project root and the rest of the path is untouched. In some cases, the module path will be longer this way, because the path goes up the tree to the project root and then back down the tree to the module.
FAQs
Transforms require module paths that have a prefix referring to the project root. Also works on `require.resolve`.
We found that babel-plugin-root-require demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.