【问题标题】:Why is my project installing the wrong Angular version?为什么我的项目安装了错误的 Angular 版本?
【发布时间】:2016-09-18 02:47:11
【问题描述】:

我的项目似乎没有最新的 Angular 代码,但我不知道为什么。

这是我的package.json

  "devDependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",

这是我的node_modules/@angular/compiler/src/metadata_resolver.js 中的一个函数,我需要修补它来修复this problem

function componentModuleUrl(reflector, type, cmpMetadata) {
    if (cpl.isStaticSymbol(type)) {
        return staticTypeModuleUrl(type);
    }
    if (isPresent(cmpMetadata.moduleId)) {
        var moduleId = cmpMetadata.moduleId;
        var scheme = getUrlScheme(moduleId);
        return isPresent(scheme) && scheme.length > 0 ? moduleId :
            "package:" + moduleId + MODULE_SUFFIX;
    }
    return reflector.importUri(type);
}

这是 Angular GitHub repository 中的相同函数(在 TypeScript 中)

function componentModuleUrl(
    reflector: ReflectorReader, type: Type<any>, cmpMetadata: Component): string {
  if (cpl.isStaticSymbol(type)) {
    return staticTypeModuleUrl(type);
  }

  const moduleId = cmpMetadata.moduleId;

  if (typeof moduleId === 'string') {
    const scheme = getUrlScheme(moduleId);
    return scheme ? moduleId : `package:${moduleId}${MODULE_SUFFIX}`;
  } else if (moduleId !== null && moduleId !== void 0) {
    throw new Error(
        `moduleId should be a string in "${stringify(type)}". See <shortened link that stackoverflow does not allow> for more information.\n` +
        `If you're using Webpack you should inline the template and the styles, see <shortened link that stackoverflow does not allow>`);
  }

  return reflector.importUri(type);
}

【问题讨论】:

    标签: angularjs angular npm


    【解决方案1】:

    【讨论】:

    • 谢谢。我不知道该怎么做。但我知道这些猜测是行不通的"@angular/common": "2.0.0#2.0.0""@angular/common": "git://angular/angular.git#2.0.0""@angular/common": "git://github.com/angular/angular.git#2.0.0"
    • 没关系。这有效:"@angular/common": "angular/angular#2.0.0"
    猜你喜欢
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 2018-01-24
    相关资源
    最近更新 更多