question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[import/no-unused-modules] not correctly handling `export { default } from 'foo'` syntax

See original GitHub issue

I’ve been really interested in using the import/no-unused-modules rule in one of my React projects, but it seems to be incorrectly reporting an error when it sees the export { default } from 'foo' syntax:

/usr/src/app/app/pages/About/index.js
  1:1  error  exported declaration 'default' not used within other modules  import/no-unused-modules

It’s been a bit tricky for me to reproduce with a smaller example, as it seems to be somewhat reliant on the Babel and Webpack plugins, but I have been able to produce a branch of my project with 95% of the files removed and still demonstrate the issue. I think I’ve gotten the problem narrowed to the following four files in that branch:

//==============================================================================
// app/init.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import Routes from './routes';

ReactDOM.render((
  <BrowserRouter>
    <Routes />
  </BrowserRouter>
), document.getElementById('root'));


//==============================================================================
// app/routes.jsx
import React from 'react';
import { Route, Switch } from 'react-router-dom';

import About from './pages/About';

export default () => (
  <Switch>
    <Route path="/about" component={About} />
  </Switch>
);


//==============================================================================
// app/pages/About/index.js
export { default } from './About';


//==============================================================================
// app/pages/About/About.jsx
import React from 'react';

export default class About extends React.Component {
  render() {
    return (
      <article>
        <header>
          About the SF Service Guide
        </header>
      </article>
    );
  }
}

Any help I could get with this would be greatly appreciated. If there’s a way for me to dump out extra logging information, I’d be willing to attach it here.


Here are the versions of relevant packages, and you can check out the package.json in the branch I linked to for the full details:

On the branch I linked to, you should be able to reproduce the problem with the following commands:

git clone https://github.com/ShelterTechSF/askdarcel-web.git -b test-unused-modules
cd askdarcel-web
npm install
npm run lint

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
richardxiacommented, Jan 28, 2020

Sounds good to me. I’m a bit busy the next couple of days, but I’ll have some time to work on this this weekend, if not earlier.

0reactions
maniatorcommented, Mar 3, 2020

@ljharb – any updates on getting what @richardxia worked on into the next release? 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

`export default let foo = ...` throws "Unexpected strict mode ...
export has strictly defined syntax, the proper syntax for default export is export default expression;. let foo = 10 is not an expression ......
Read more >
export - JavaScript - MDN Web Docs
The export default syntax allows any expression. As a special case, functions and classes are exported as declarations, not expressions, and ...
Read more >
`export default thing` is different to `export { thing as default }`
Imports are references, not values. Here's an import: import { thing } from './module.js';. In the above example, thing is the same as...
Read more >
no-restricted-exports - ESLint - Pluggable JavaScript Linter
Rule Details. This rule disallows specified names from being used as exported names. Options. By default, this rule doesn't disallow any names.
Read more >
ECMAScript 6 modules: the final syntax - 2ality
JavaScript does not have built-in support for modules, ... An ECMAScript 6 module can pick a default export, the most important exported ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found