我正在尝试使用 webpack 2 设置 angular 2,但出现构建错误。
我刚刚导入了 @angular/platform-browser-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"
]
}