【问题标题】:Errors After Updating Angular 2更新 Angular 2 后的错误
【发布时间】:2017-07-22 18:01:39
【问题描述】:

更新我的 package.json 后,我收到以下错误。我很确定它来自 node_modules 文件夹。当我运行该应用程序时,它像以前一样工作正常,但 webpack: 无法编译。我能做些什么来解决这个问题?

[默认] /Users/Desktop/ 中的错误 项目/目录/node_modules/@types/jasmine/index.d.ts:39:45 找不到名称“keyof”。

[默认] /Users/Desktop/Project/directory/node_modules/@types/jasmine/index.d.ts:39:51 中的错误 '=' 预期。

[默认] /Users/Desktop/directory/node_modules/@types/lodash/index.d.ts:244:12 中的错误 重复标识符“_”。

[默认] /Users/Desktop/Project/directory/node_modules/@types/lodash/index.d.ts:244:15 中的错误 找不到命名空间“_”。

[默认] /Users/Desktop/Project/directory/node_modules/@types/lodash/index.d.ts:246:24 中的错误 找不到名称“部分”。

[默认] /Users/Desktop/Project/directory/node_modules/@types/lodash/index.d.ts:248:18 中的错误 重复标识符“_”。

 //new error
GET http://localhost:4200/node_modules/zone.js/dist/zone.js 
localhost/:11 GET http://localhost:4200/node_modules/primeng/resources/themes/omega/theme.css 
localhost/:18 GET http://localhost:4200/node_modules/primeng/resources/primeng.min.css 
localhost/:24 GET http://localhost:4200/node_modules/core-js/client/shim.min.js 
localhost/:26 GET http://localhost:4200/node_modules/reflect-metadata/Reflect.js 
localhost/:27 GET http://localhost:4200/systemjs.config.js 
(index):11 GET http://localhost:4200/node_modules/primeng/resources/themes/omega/theme.css 
(index):18 GET http://localhost:4200/node_modules/primeng/resources/primeng.min.css 
(index):21 GET http://localhost:4200/node_modules/primeng/resources/themes/omega/theme.css 
(index):24 GET http://localhost:4200/node_modules/core-js/client/shim.min.js 
(index):25 GET http://localhost:4200/node_modules/zone.js/dist/zone.js 
(index):26 GET http://localhost:4200/node_modules/reflect-metadata/Reflect.js 
(index):27 GET http://localhost:4200/systemjs.config.js  

新的 package.json

    {
      "name": "directory",
      "version": "0.0.0",
      "license": "MIT",
      "angular-cli": {},
      "scripts": {
        "start": "ng serve",
        "lint": "tslint \"src/**/*.ts\"",
        "test": "ng test",
        "pree2e": "webdriver-manager update",
        "e2e": "protractor"
      },
      "private": true,
      "dependencies": {
        "@angular/common": "~2.4.9",
        "@angular/compiler": "~2.4.9",
        "@angular/core": "~2.4.9",
        "@angular/forms": "~2.4.9",
        "@angular/http": "~2.4.9",
        "@angular/platform-browser": "~2.4.9",
        "@angular/platform-browser-dynamic": "~2.4.9",
        "@angular/router": "~3.4.9",
        "@types/lodash": "^4.14.50",
        "angular-2-data-table": "^0.1.2",
        "angular2-datatable": "^0.5.2",
        "core-js": "^2.4.1",
        "lodash": "^4.17.4",
        "ng2-date-picker": "^0.2.1",
        "ng2-file-upload": "^1.1.2",
        "ng2-modal": "0.0.25",
        "ng2-pagination": "^2.0.1",
        "ng2-table": "^1.3.2",
        "primeng": "^2.0.1",
        "rxjs": "5.2.0",
        "tinymce": "^4.5.2",
        "ts-helpers": "^1.1.1",
        "zone.js": "^0.7.7"
      },
      "devDependencies": {
        "@types/jasmine": "^2.2.30",
        "@types/node": "^7.0.5",
        "angular-cli": "1.0.0-beta.28.3",
        "codelyzer": "3.0.0-beta.0",
        "jasmine-core": "2.5.2",
        "jasmine-spec-reporter": "3.2.0",
        "karma": "1.5.0",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-jasmine": "^1.0.2",
        "karma-remap-istanbul": "^0.6.0",
        "protractor": "5.1.1",
        "ts-node": "2.1.0",
        "tslint": "4.5.1",
        "typescript": "~2.2.1"
      }
    }

旧包.json

{
  "name": "directory",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@types/lodash": "^4.14.50",
    "angular-2-data-table": "^0.1.2",
    "angular2-datatable": "^0.5.2",
    "core-js": "^2.4.1",
    "lodash": "^4.17.4",
    "ng2-date-picker": "^0.2.1",
    "ng2-file-upload": "^1.1.2",
    "ng2-modal": "0.0.24",
    "ng2-pagination": "^2.0.1",
    "ng2-table": "^1.3.2",
    "primeng": "^1.1.4",
    "rxjs": "5.0.0-beta.12",
    "tinymce": "^4.5.2",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.18",
    "codelyzer": "1.0.0-beta.1",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "~2.0.3"
  }
}
//system.config.js

 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      "ng2-modal": "node_modules/ng2-modal",
        "ng2-ckeditor": "npm:ng2-ckeditor",



        // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
        'primeng':                   'npm:primeng',

        // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'ng2-pagination': 'npm:ng2-pagination' // add mapping for ng2-pagination

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
        "ng2-ckeditor": {

            "ng2-modal": {"main": "index.js", "defaultExtension": "js"},
            app: {
                main: './main.js',
                defaultExtension: 'js'
            },
        },
        'ng2-pagination': { //add configuration to load
        main: './index.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

【问题讨论】:

  • 如果您还有 typings 文件夹,请将其删除。
  • 我在哪里可以找到typings文件夹,你的意思是typings.d.ts?
  • 好吧,如果您在应用程序主文件夹中看不到它,则意味着没有打字文件夹。
  • 您是否尝试删除文件夹 node_modules 并再次运行npm install
  • 角度 4 的 2.2.1

标签: angular


【解决方案1】:

好吧,在阅读了配置代码之后,您可以看到 app 包的放置位置,将您的 package 条目替换为这个:

packages: {
      /*"ng2-ckeditor": {        
        main: './index.js',
        defaultExtension: 'js'      
      },*/
      "ng2-modal": {
        defaultExtension: "js"
      },
      'ng2-pagination': { //add configuration to load
        defaultExtension: 'js'
      },
      primeng: {
        defaultExtension: 'js'
      }
      rxjs: {
        defaultExtension: 'js'
      },
      app: {
        main: './main.js',
        defaultExtension: 'js'
      }
}

我无意将此添加为答案,但评论太多了。

【讨论】:

  • 您的服务器是从您的 main.ts 文件和 node_modules 文件夹所在的同一文件夹运行的,对吗?
猜你喜欢
  • 2017-11-03
  • 1970-01-01
  • 1970-01-01
  • 2018-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-17
  • 2017-07-20
相关资源
最近更新 更多