I am currently working with the following webpack.config.js file
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-.+))/]
}
]
}
};
In addition to that, I have created this tsconfig.json file
{
"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
}
Upon running the tsc
command, everything runs smoothly.
ng2-auto-complete (master)$ tsc --declaration
ng2-auto-complete (master)$
However, when executing the webpack
command, TypeScript compile errors start showing up.
ng2-auto-complete (master)$ webpack
ts-loader: Using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c38355c313e3f3c45443c493d7d737d7">[email protected]</a> 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)$
If anyone knows how to address the TS2304 errors while using the webpack
command, your help would be greatly appreciated.
Note that the node_modules
directory has been excluded in the tsconfig.json
file like so:
"exclude": [ "node_modules" ],
Also, the type definitions are present in the node_modules
directory as evidenced by the devDependencies section below:
"devDependencies": {
"@types/core-js": "^0.9.32",
"@types/node": "^6.0.31"
Additionally, attempts were made using a typings.json
file and typings directory without success.
{
"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"
}
}
For reference, here are the versions of various tools being used:
$ node --version
v5.7.1
$ npm --version
3.6.0
$ tsc --version
Version 2.0.0
If you have any insights on resolving the TS2304 errors encountered with the webpack
command, please do share your expertise. Thank you!