我有以下 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)$
我不知道我错过了什么网络包和类型脚本编译。
node_modules
已被排除在 tsconfig.json
之外
“排除”: [ “ node _ module” ],
和类型定义都在 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错误?