Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpack-fix-default-import-plugin

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-fix-default-import-plugin

Webpack plugin to fix default import for non ES6 modules

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
967
decreased by-15.99%
Maintainers
1
Weekly downloads
 
Created
Source

Webpack Fix Default Import Plugin

Why?

With Babel transpiler you could write:

import React from 'react';
import ReactDOM from 'react-dom';

In this case Babel will be able to resolve module.exports.default as modules.exports if module.exports.default is not defined.

It doesn't work with TypeScript compiler which targets ES5, so we have to use:

import * as React from 'react';
import * as ReactDOM from 'react-dom';

One well know workaround for this issue is to use TWO transpilers, typescript first targeted to ES6 and Babel second targeted to ES5. Extra transpilation takes more time and break source maps.

The other solution is to hook into webpack's require() implementation and polyfill module.exports.default if it is blank and module is not ES6 module.

This plugin hooks into require() and try to polyfill module.exports.default.

Installation

npm install --save-dev webpack-fix-default-import-plugin

webpack.config.js example:

var FixDefaultImportPlugin = require('webpack-fix-default-import-plugin');

module.exports = {
  ...
  plugins: [
    ...
    new FixDefaultImportPlugin()
  ],
};

tsconfig.json example:

{
  "compilerOptions": {
    "sourceMap": true,
    "noImplicitAny": true,
    "noEmitHelpers": true,
    "allowSyntheticDefaultImports": true,   // required
    "module": "commonjs",                   // required
    "target": "es5",                        // required
    "jsx": "react"
  },
  "exclude": [
    "node_modules",
    "typings/globals"
  ]
}

tslint.json example:

{
  ...
  "rules": {
    ...
    "no-unused-variable": [true, {"ignore-pattern": "^(React|ReactDOM)$"}],
    "import-name": false,
    "no-default-export": false
  }
}

Keywords

FAQs

Package last updated on 10 May 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc