
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
import-local
Advanced tools
Let a globally installed package use a locally installed version of itself if available
Let a globally installed package use a locally installed version of itself if available
Useful for CLI tools that want to defer to the user's locally installed version when available, but still work if it's not installed locally. For example, AVA and XO uses this method.
npm install import-local
import importLocal from 'import-local';
if (importLocal(import.meta.url)) {
console.log('Using local version of this package');
} else {
// Code for both global and local version here…
}
You can also pass in __filename when used in a CommonJS context.
The resolve-from package allows you to resolve a module path from a given root directory. It's similar to import-local in that it helps with module resolution, but it doesn't automatically defer to a local version of a package.
Require-local is another package that allows for requiring modules from a local context. It's similar to import-local but does not provide the automatic deferring mechanism to local versions when a global version is run.
Linklocal can link local dependencies for development purposes. It's similar to import-local in that it helps with using local versions of packages, but it works by creating symlinks rather than deferring when a global version is executed.
FAQs
Let a globally installed package use a locally installed version of itself if available
We found that import-local 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.