我有以下webpack.config.js
var path = require("path");
var webpack = require('webpack');
module.exports = {
entry: {
'ng2-auto-complete': path.join(__dirname, 'src', 'index.ts')
},
resolve: {
extensions: ['', '.ts', '.js', '.json', '.css', '.html']
},
output: {
path: path.join(__dirname, 'dist'),
filename: "[name].umd.js",
library: ["[name]"],
libraryTarget: "umd"
},
externals: [
/^rxjs\//, //.... any other way? rx.umd.min.js does work?
/^@angular\//
],
devtool: 'source-map',
module: {
loaders: [
{ // Support for .ts files.
test: /\.ts$/,
loaders: ['ts', 'angular2-template-loader'],
exclude: [/test/, /node_modules\/(?!(ng2-.+))/]
}
]
}
};
和以下tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"noEmitHelpers": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": true,
"allowUnusedLabels": true,
"noImplicitAny": false,
"noImplicitReturns": false,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": false,
"allowSyntheticDefaultImports": true,
"suppressExcessPropertyErrors": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "dist",
"baseUrl": "src"
},
"files": [
"src/index.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"buildOnSave": false
}
当我tsc
按以下方式运行命令时,一切正常。
ng2-auto-complete (master)$ tsc --declaration
ng2-auto-complete (master)$
当我运行webpack
命令时,它显示打字稿编译错误。
ng2-auto-complete (master)$ webpack
ts-loader: Using typescript@2.0.0 and /Users/allen/github/ng2-auto-complete/tsconfig.json
Hash: bd6c50e4b9732c3ffa9d
Version: webpack 1.13.2
Time: 5041ms
Asset Size Chunks Chunk Names
ng2-auto-complete.umd.js 24.4 kB 0 [emitted] ng2-auto-complete
ng2-auto-complete.umd.js.map 28.4 kB 0 [emitted] ng2-auto-complete
+ 11 hidden modules
ERROR in /Users/allen/github/ng2-auto-complete/node_modules/@angular/platform-browser/src/dom/dom_renderer.d.ts
(18,37): error TS2304: Cannot find name 'Map'.
ERROR in /Users/allen/github/ng2-auto-complete/node_modules/@angular/platform-browser/src/dom/dom_adapter.d.ts
(96,42): error TS2304: Cannot find name 'Map'.
ERROR in /Users/allen/github/ng2-auto-complete/node_modules/@angular/platform-browser/src/web_workers/worker/location_providers.d.ts
(21,86): error TS2304: Cannot find name 'Promise'.
...
ng2-auto-complete (master)$
我不知道Webpack和Typescript编译缺少什么。
node_modules
已被排除在 tsconfig.json
“ exclude”:[“” node_modules“],
类型定义在那里 node_modules
"devDependencies": {
"@types/core-js": "^0.9.32",
"@types/node": "^6.0.31"
我也尝试使用typings.json
和键入目录没有成功。
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160815222444"
}
}
仅供参考,版本
$ node --version
v5.7.1
$ npm --version
3.6.0
$ tsc --version
Version 2.0.0
如何使用webpack
命令消除TS2304错误?