1

我正在尝试使用 webpack 2 设置 angular 2,但出现构建错误。

我刚刚导入了 @angular/platform-b​​rowser-dynamic 但它在屏幕上显示了很多错误。找不到模块'错误找不到名称'全局'。是其中之一

C:\Users\T12449\Desktop\angular\hello-angular\node_modules\zone.js\lib\zone-spec\wtf.ts (156,80) 中的错误:错误 TS2304:找不到名称“全局”。

C:\Users\T12449\Desktop\angular\hello-angular\node_modules\zone.js\lib\zone-spec\fake-async-test.ts (268,80) 中的错误:错误 TS2304:找不到名称“全局” '。

C:\Users\T12449\Desktop\angular\hello-angular\node_modules\zone.js\lib\node\node.ts (18,93) 中的错误:错误 TS2304:找不到名称“全局”。

我的 webpack.config.js

module.exports = {
   entry: './src/main.ts',
   output: {
   filename: '[name].[ext]'
 },
 resolve: {
  extensions: ['.ts', '.tsx', '.js']
 },
 module: {
  loaders: [
    { test: /\.tsx?$/, loader: 'ts-loader' }
   ]
 }
}

包.json

{
  "name": "hello-angular",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack"
    },
  "author": "",
  "license": "ISC",
  "devDependencies": {
  "@types/core-js": "^0.9.41",
  "ts-loader": "^2.0.3",
  "typescript": "^2.2.2",
  "webpack": "^2.3.3",
  "webpack-dev-server": "^2.4.2"
},
"dependencies": {
    "@angular/common": "^4.0.1",
    "@angular/compiler": "^4.0.1",
    "@angular/core": "^4.0.1",
    "@angular/platform-browser": "^4.0.1",
    "@angular/platform-browser-dynamic": "^4.0.1",
    "rxjs": "^5.0.1",
    "zone.js": "^0.8.4"
  }
}

main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
const a :number = 0;

tsconfig.json

{
  "compilerOptions": {
    "removeComments": true,
    "sourceMap": false,
    "module": "commonjs",
    "noImplicitAny": false,
    "target": "es2015",
    "typeRoots": [
      "../node_modules/@types"
    ],
    "types": [
      "core-js"
    ]
},
"exclude": [
  "../node_modules"
]
}
4

1 回答 1

3

您是否尝试过设置:

typings.d.ts   //If you don't see this file under src folder create one

和:

declare var global: any

如此处所述:https ://github.com/angular/angular-cli#3rd-party-library-installation

于 2017-04-11T19:26:01.210 回答