Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue May 10, 2018 · 2 comments · Fixed by #24491
Closed

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

ghost opened this issue May 10, 2018 · 2 comments · Fixed by #24491
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented May 10, 2018

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 @sandersn

@sandersn
Copy link
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.

@sandersn
Copy link
Member

@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.

@sandersn sandersn added the Fixed A PR has been merged for this issue label May 30, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants