从2升级到4后,编译Angular项目失败

时间:2017-06-22 14:34:10

标签: angular typescript

我刚刚将角度项目从2升级到4。 我这样做了:
1 - 删除/ node_modules /文件夹
2-运行:

class CustomDeepcopy(object):

    a = SomeSimpleObject()
    b = SomeBigObject()

    def dont_deepcopy(self):
        return ['b']

    def __deepcopy__(self,memo):
        for attr in self.dont_deepcopy():
            val = getattr(self,attr,None)
            if val is not None:
                 memo[id(val)]=val
        deepcopy_method = self.__deepcopy__
        self.__deepcopy__ = None
        result = copy.deepcopy(self,memo)
        self.__deepcopy__ = deepcopy_method
        return result

为了将最新版本添加到package.json

3-run npm install
++这里有一些奇怪的东西,在树的最后我看到: enter image description here

4- run ng build

我得到的错误信息是:

npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest --save

当我转到上述类之一时,我看到一条错误消息:  enter image description here

说'找不到类型对象'

我的Java背景告诉我,我使用的编译器以不同于库中使用的方式解释“对象” 事实上,我希望'Object'可以是具体的类或接口。 有什么建议吗?

这是我的package.json

    ERROR in PATH/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts (133,11): All declarations of 'WeakMap' must have identical type parameters.

ERROR in PATH/node_modules/typescript/lib/lib.es2015.iterable.d.ts (124,11): All declarations of 'WeakMap' must have identical type parameters.

ERROR in PATH/node_modules/typescript/lib/lib.es2015.collection.d.ts (45,11): All declarations of 'WeakMap' must have identical type parameters.

ERROR in PATH/node_modules/@types/lodash/index.d.ts (19417,15): All declarations of 'WeakMap' must have identical type parameters.

1 个答案:

答案 0 :(得分:3)

您应该从"typescript": "^2.3.4"中删除dependencies条目,并将devDependencies中的"typescript": "^2.3.4"替换为2.2.0。最新的Angluar版本要求打字稿版本至少为@types/lodash

要注意更多事项:

  • 将您的devDependencies移至4.14.66并将其更新为@angular/compiler-cli
  • 从依赖项中删除angular-cli
  • "@angular/cli": "1.1.3"替换为/<@[^>]*>/g

最后一点可能会引起一些额外的问题,但请检查更改日志以了解更改。

另请查看here以获取更多升级提示