【问题标题】:angular 2 webpack 2 error cannot find name 'global'angular 2 webpack 2 错误找不到名称“全局”
【发布时间】:2017-09-07 03:14:45
【问题描述】:

我正在尝试使用 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' }
   ]
 }
}

package.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"
]
}

【问题讨论】:

标签: angular typescript webpack webpack-2 ts-loader


【解决方案1】:

您是否尝试过设置:

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

【讨论】:

  • 该链接不再相关
猜你喜欢
  • 2018-07-31
  • 2023-04-04
  • 2016-11-29
  • 2016-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-27
  • 2022-01-23
相关资源
最近更新 更多