Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

import-global

sindresorhus584.4kMIT1.1.1TypeScript support: included

Import a globally installed module

import, global, package, module, globally, npm, yarn, packages, require

readme

import-global

Import a globally installed module

Please don't use this unless absolutely necessary. Local dependencies should be preferred.

Install

npm install import-global

Usage

npm install --global cat-names
import {importGlobal} from 'import-global';

const {default: catNames} = await importGlobal('cat-names');

catNames.random();
//=> 'Snuggles'

API

importGlobal(moduleName)

Throws if the module cannot be found.

importGlobalSilent(moduleName)

Returns undefined instead of throwing if the module cannot be found.

moduleName

Type: string

What you would use in import().