首页 文章

在Angular 2应用程序中集成JQuery后的编译错误

提问于
浏览
1

我有一个用npm管理的Angular 2项目,我最近跑了

typings install dt~jquery --save --global

将JQuery类型定义添加到我的项目中 .

npm然后按预期将此类型定义文件下载到目录node_modules .

现在的问题是,Typescript编译器(使用 npm run tsc:w )抱怨:

$ npm run tsc:w

node_modules/@types/jquery/index.d.ts(3246,5):错误TS2300:重复标识符'export =' . typings / globals / jquery / index.d.ts(601,5):错误TS2374:重复的字符串索引签名 . typings / globals / jquery / index.d.ts(2850,5):error TS2374:重复的字符串索引签名 . typings / globals / jquery / index.d.ts(2851,5):错误TS2375:重复的数字索引签名 . typings / globals / jquery / index.d.ts(3224,5):错误TS2300:重复标识符'export =' . 18:48:59 - 编译完成注意文件更改 .

任何想法如何解决这个问题?

2 回答

  • 0

    Transpiler会出现重复的定义错误,因为您似乎已将定义文件安装到项目的多个位置:

    node_modules/@types/jquery/index.d.ts
    typings/globals/jquery/index.d.ts
    

    尝试通过键入以下行来卸载 @types/jquery 模块:

    npm remove @types/jquery --save-dev
    
  • 3

    我有同样的错误 . 我正在关注打字稿的udemy课程 .

    他解释了 typings 然后 @types ,但他在@types视频的开头真的很快他说

    删除2件事:

    • typings 文件夹

    • typings.json

    我完全错过了他第一次说的话 .

    另外,我的SystemJS缺少 Map 部分(我认为没有必要,但我想是的 . )

    SystemJS.config({
        map: {
            "jQuery": "node_modules/jquery/dist/jquery.min.js"
        },
        baseURL: '/',
        packages: {
            '/': {
                defaultExtension: 'js'
            }
        }
    });
    

    一旦我掌握了所有这些,一切都会奏效 .

相关问题