Galooshi / import-js

A tool to simplify importing JS modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

namedExports solved the 'No JS module to import for Redirect' problem

dagolinuxoid opened this issue · comments

Since 2.1.0 ImportJS finds your named exports automatically. Most likely you don't need this option.

Apparently I need this for some modules. For example { connect } from 'react-redux', React from 'react' libraries and others imported as expected. But things from 'react-router-dom' gave me a headache =).
My package.json is valid and has 'react-router-dom' as a dependency library. The solution is

module.exports = {
  excludes: ['./public/**'],
  emptyLineBetweenGroups: false,
  sortImports: false,
  groupImports: false,
  minimumVersion: '4.0.2',
  namedExports: {
    'react-router-dom': ['Route', 'Redirect']
  }
};

I don't know what is special with the particular library but with the settings importing works.

Import-js will make an attempt at finding named exports from a module, but it won't always do so. In the case of react-router-dom, I can't find a reference to Route or Redirect in the module's main js file. That doesn't mean the export isn't there, just that it's harder to find. It will most likely involve executing/running the code which import-js won't do (for performance and complexity reasons).

Glad you found a workaround!

Do you think we should update the docs a little for this? Perhaps we should mention namedExports as a solution in relation to the Since import-js ... line. If so, would you be able to take it on and file a PR?