
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
babel-resolver
Advanced tools
Resolve modules from any directory.
import User from '../../models/User';
Becomes:
import User from 'models/User';
In app/index.js:
require('babel-core/register')({
presets: ['es2015'], // required for 'import'
resolveModuleSource: require('babel-resolver')(__dirname)
});
require('./app');
In app/app.js:
import User from 'models/User';
// => resolves: "app/models/User.js"
This example uses Babel 6 and babel-core/register
.
If you wish to define options in .babelrc, use the Babel Resolver Plugin instead.
Note: Run rm -rf ~/.babel.json
if you're seeing errors.
Note2: Babel's resolveModuleSource
is only called when you use import
, not require
.
Also, keep in mind that you must provide absolute directory paths to babel-resolver
.
In app/index.js:
var path = require('path');
var localModulesDir = __dirname;
var anotherDirToCheck = path.resolve(__dirname, 'lib');
require('babel-core/register')({
presets: ['es2015'],
resolveModuleSource: require('babel-resolver')(localModulesDir, anotherDirToCheck)
});
require('./app');
In app/app.js:
import User from 'models/User';
// => resolves: "app/models/User.js"
import somethingInLib from 'somethingInLib';
// => resolves: "app/lib/somethingInLib.js"
npm i babel-resolver --save
rm -rf ~/.babel.json
While setting NODE_PATH=app
is a perfectly valid solution, babel-resolver
is more explicit and lets you avoid mucking around with environment variables.
MIT
FAQs
Resolve modules from any directory.
The npm package babel-resolver receives a total of 431 weekly downloads. As such, babel-resolver popularity was classified as not popular.
We found that babel-resolver 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.