Skip to content

Discourage mixing CJS and ES6 module syntax in docs #3571

Closed

Description

@wyuenho

Experience has shown that it is easy to fall into a trap like this:

// a.js
module.exports = function foo () {};

// b.js
import a from './a.js'; // error, no default member found in a
a.foo();

Much code has been written like this and it used to work in Webpack 2 beta, which only exacerbates the problem of spec-incompliant code like above. Webpack's doc seems to advertise the ability to mix and match different module syntax without mentioning gotchas. I suggest that Webpack should actively discourage this practice when possible, and point people to tools such as eslint-plugin-import to help fix their code.

Activity

  1. changed the title [-]Discourage mixing CJS and ES6 module syntax[/-] [+]Discourage mixing CJS and ES6 module syntax in docs[/+] on Dec 25, 2016
  2. bebraw commented on Dec 25, 2016

    @bebraw
    Contributor

    Can you move this to the doc repo? Thanks.

  3. Jessidhia commented on Dec 25, 2016

    @Jessidhia

    That a.js actually is still supposed to work AFAIK...

    It should only break if there is an import or export in the same file. Since it's very unlikely a user would use both export and module.exports in the same file, it's more likely to happen if there's an import and module.exports / exports.

    I wonder if there's a way to make module / exports be ReferenceError, but only in the module parse goal...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions