将Angular 5更新为6.rc0会导致打包问题

时间:2018-03-27 12:37:41

标签: angular browser webpack msgpack

我目前尝试从角度5更新到6.rc0。我将包json更改为:

{
  "name": "angular5to6",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.0-rc.0",
    "@angular/cdk": "6.0.0-beta.5",
    "@angular/common": "6.0.0-rc.0",
    "@angular/compiler": "6.0.0-rc.0",
    "@angular/core": "6.0.0-rc.0",
    "@angular/forms": "6.0.0-rc.0",
    "@angular/http": "6.0.0-rc.0",
    "@angular/material": "6.0.0-beta.5",
    "@angular/platform-browser": "6.0.0-rc.0",
    "@angular/platform-browser-dynamic": "6.0.0-rc.0",
    "@angular/router": "6.0.0-rc.0",
    "core-js": "2.5.3",
    "material-design-icons": "^3.0.1",
    "roboto-fontface": "^0.9.0",
    "rxjs": "^5.6.0-forward-compat.2",
    "zone.js": "0.8.20"
  },
  "devDependencies": {
    "@angular/cli": "6.0.0-beta.6",
    "@angular/compiler-cli": "6.0.0-rc.0",
    "@angular/language-service": "6.0.0-rc.0",
    "@types/autobahn": "^0.9.38",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "8.10.0",
    "autobahn": "^18.3.1",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "2.7.2"
  }
}

我在更新到node 8.10.0后更新了所有依赖项和ng build,当我打开浏览器并尝试运行构建时出现以下问题:

index.js:43 Uncaught ReferenceError: global is not defined
at Object.../node_modules/buffer/index.js (index.js:43)
at __webpack_require__ (bootstrap:74)
at Object.../node_modules/safe-buffer/index.js (index.js:2)
at __webpack_require__ (bootstrap:74)
at Object.../node_modules/msgpack5/index.js (index.js:3)
at __webpack_require__ (bootstrap:74)
at Object.../node_modules/autobahn/lib/autobahn.js (autobahn.js:22)
at __webpack_require__ (bootstrap:74)
at Object.../node_modules/autobahn/index.js (index.js:14)
at __webpack_require__ (bootstrap:74)

出于某种原因,似乎webpack不会将所有内容呈现为与浏览器兼容的代码。

[UPDATE]

似乎有几个外部包破了。我不知道为什么。它们与棱角无关!?在这种情况下,它是msgpack5包。

1 个答案:

答案 0 :(得分:1)

我发现了导致问题的问题。我向angular/cli project开了一个新问题。我不得不从

降级
"@angular/cli": "6.0.0-beta.6"

"@angular/cli": "1.7.3"

多数民众赞成!

[更新]使用polyfill

可以更新最新的CLI / angular 6 with autobahn
(window as any).global = window;
(window as any).process = window;
(window as any).Buffer = window;
(window as any).process.browser = true;
(window as any).process.version = '';
(window as any).process.versions = {node: false};