2020-12-08 21:15

Cannot start application: "cannot find type definition for file for 'core-js'"

Getting the current error on app start

node_modules/angular2-select/src/select-dropdown.component.d.ts(1,1): error TS2688: Cannot find type definition file for 'core-js'.
node_modules/angular2-select/src/select.component.d.ts(1,1): error TS2688: Cannot find type definition file for 'core-js'.

tsconfig.json refers to "node_modules//**/*.d.ts"

I don't have the folder by default. If I install with npm install /core-js then when I try to start application with npm run start I get loads of errors:

typings/globals/core-js/index.d.ts(3051,5): error TS2300: Duplicate identifier 'export='.

(removing typings/globals/core-js just gives different errors)

Workaround: If I remove the triple-slash directive at the top of the two *.d.ts files mentioned above then the issue goes away. (others have fixed with a similar hack)

I have spent a few hours reading docs and I can't figure out how to do this properly. Possibly upgrading to Typescript 2.0 beta might fix it, but haven't tried yet.

A full removal of node_modules, typings and then a npm cache clean, followed by a npm install doesn't fix the issue.

No idea what's going on here because the angular2-select-demo works ok on the same environment. Any TypeScript experts able to help explain what's going on?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39636691 weixin_39636691 5月前

    Which version did you use? I made a mistake with the types in alpha.9 which should be fixed in alpha.10.

    What does your tsconfig.json file look like? You might need to exclude some of the installed types to prevent the duplicate identifier error. However, I am also new to typescript and the type defenitions, so I am not sure if I can help you out.

    Maybe I should make /core-js a peer dependency to make sure that it is installed by npm (I used npm for installing the types, and I hope everyone will start doing that, because having typings as a second package manager is a bit double in my opinion). It could however be that some other package references the same type defenition that is installed in the typings directory, so that it is installed twice at different locations (at least, that is what I think, I am not sure about this). I think that if tsc 'sees' both types it will throw the duplicate identifier error, so one of them should be excluded for typescript compilation.

    But again, this is just a guess. I didn't have the time yet to dive into the typescript details...

    点赞 评论 复制链接分享
  • weixin_39697660 weixin_39697660 5月前
    • Currently using alpha.12.
    • tsconfig.json matches that in angular2-select-demo
    • typescript 2.0.3

    I can now reproduce the issue in angular2-select-demo

    Change app.component.ts line 89 to include the SelectComponent type

    ('singleSelectComponent') singleSelectComponent: SelectComponent;

    and then import the type:

    import {SelectComponent} from "angular2-select/src/select.component";

    and run with npm run build - you should see the same two errors I'm getting.

    This means I have a better workaround by removing the type from the declaration ie

    ('singleSelectComponent') singleSelectComponent;

    works ok (tsconfig.json: noImplicitAny must be false)

    I guess this issue should be fixed because we've lost type information. I've spent many hours trying to crack it with various approaches. The error is clear enough - though it seems like it should work, because the reference to core-js is defined in typings/index.d.ts.

    点赞 评论 复制链接分享
  • weixin_39697660 weixin_39697660 5月前

    I now have a more robust fix, which is "don't use typings". It seems that an npm install is sufficient, and will work from a clean install. This seems to be best practice, as described here

    点赞 评论 复制链接分享
  • weixin_39636691 weixin_39636691 5月前

    Thanks for looking into this. The easiest solution seems to be using angular-cli, which saves the trouble of defining a systemjs config (I think that angular-cli by now uses webpack instead of systemjs, but that is unrelated :). I will close the issue and will advice the use of angular-cli from now on. For another project I also didn't get building/testing to work with gulp/systemjs.

    点赞 评论 复制链接分享