Socket
Socket
Sign inDemoInstall

babel-plugin-try-import

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-try-import

try import module


Version published
Maintainers
1
Created

Readme

Source

babel-plugin-try-import

try import module in webpack

what does this plugin do

convert

let react = tryImport('react');

into

let react = function () {
  let temp;

  try {
    temp = require('react').default;
  } catch (error) {}

  return temp;
}()

so that webpack won't throw error while react is not exist

convert

let hasReact = hasModule('react');

into

let hasReact = function () {
  let temp = false;

  try {
    require.resolveWeak('react');

    temp = true;
  } catch (error) {}

  return temp;
}()

so that you can check if a module exists

Keywords

FAQs

Last updated on 14 Jan 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc