Skip to content
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

Duplicate identifier error when 2 projects, main and dependent, both supply type definitions for a knockout/jquery library #12286

Closed
mKlus opened this issue Nov 16, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@mKlus
Copy link

mKlus commented Nov 16, 2016

I have VS solution that has multiple projects.
There is a ProjectA that imports jquery and knockout and ProjectB that imports class from ProjectA and also imports knockout and jquery.
When I compile the solution (or projectB) in VS 2015 Update 3 with TS 2.0.6 installed I get the below errors.

2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(623,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(2872,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(2873,5): error TS2375: Build:Duplicate number index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\jquery\index.d.ts(3246,5): error TS2300: Build:Duplicate identifier 'export='. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(8,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(14,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(18,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(38,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(160,5): error TS2374: Build:Duplicate string index signature. 2>D:\Temp\TSProject\TSProjectA\node_modules\@types\knockout\index.d.ts(682,2): error TS2300: Build:Duplicate identifier 'export='. 2>D:\Temp\TSProject\TSProjectMain\node_modules\@types\jquery\index.d.ts(3246,5): error TS2300: Build:Duplicate identifier 'export='. 2>D:\Temp\TSProject\TSProjectMain\node_modules\@types\knockout\index.d.ts(682,2): error TS2300: Build:Duplicate identifier 'export='.

I have attached a simplified solution where the issue is reproducible.

TSProject.zip

Seems to be related to issue #10968.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 16, 2016

this looks like the same issue as #6496.

The declaration files for Jquery and knockout are declared in the global scope. this means that there is only one of them that can exist at a time. this results to conflicts once two files exist on disk.

The correct fix is to update the declaration files to be authored as modules instead of global, since they are rely not global.

as a workaround, you can add a path mapping entry in your tsconfig.json to make sure the second set of files are never loaded.

// TSProjectMain/tsconfig.json
{
    "compileOnSave": true,
    "compilerOptions": {
        "lib": [ "dom", "es2015.promise", "es5", "scripthost" ],
        "module": "amd",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es5",
        "baseUrl": "./",
        "paths": {
            "*" : ["../TSProjectA/node_modules/@types/*", "./node_modules/@types/*", "*"]
        },
        "types": []
    }
}

Alternatively, do not install @types\jquery in your second project, since your first project adds them already.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 16, 2016
@AdrienTorris
Copy link

Add a 'paths' section to my tsconfig.json worked perfectly for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants