Skip to content

Duplicate identifier error in services for commonjs module.exports.prop =  #24024

Closed

Description

TypeScript Version: 2.9.0-dev.20180510

Code

a.js

module.exports = class C {};
module.exports.D = class D {};

b.js

const a = require("./a");

Open the two tabs side-by-side in an editor. Initially there is no error, but when you make any edit (e.g., adding a newline) to b.js, then module.exports.D in a.js is marked with an error Duplicate identifier 'D'. (Making any edit to a.js will make it go away, but then editing b.js makes it come back...)

CC Nathan Shively-Sanders (@sandersn)

Activity

  1. ghost added
    BugA bug in TypeScript
    on May 10, 2018
  2. sandersn commented on May 29, 2018

    @sandersn
    Member

    Note that adding a third line in a.js, var d = new D(), causes a crash in resolveName, even from the command line. I'll file that as a separate bug.

  3. sandersn commented on May 30, 2018

    @sandersn
    Member

    Andy (Andrewkraft) (@Andy-MS) helped me find a repro that works from the command line. Put the require in the same file:

    var wat = require('./test')
    module.exports = class C {}
    module.exports.D = class D { }

    Note that the require has to be first. My current hypothesis is that getCommonJsExportEquals creates a merged symbol which is !== the symbol for class D, thereby evading the check I added in #24466. I have a simpler fix that I will put up shortly.

  4. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions