try-import

Try to import a module, returning undefined if failed.

Usage no npm install needed!

<script type="module">
  import tryImport from 'https://cdn.skypack.dev/try-import';
</script>

README

Try Import Travis CI Build Status

Try to import a module, returning undefined if failed.

NPM Badge

Install

npm install try-import

Usage

const tryImport = require("try-import");

tryImport("name");
//=> () => { ... }

tryImport.resolve("name");
//=> 'C:\Users\richi\Documents\GitHub\try-import\node_modules\name\src\index.js'

API

tryImport(name)

name

Type: string

The module to try to import.

tryImport.resolve(name)

name

Type: string

The module to try to resolve.