Citizen Citizen - 13 days ago 10
Javascript Question

TypeScript duplication issue on Mac only (webpack compilation)

I have an TypeScript app.
I compile with webpack, and under Windows I don't have any issue.
Under MacOS, I have thousands errors because of

node_modules
folder.

Can you help me understand why I can compile on Windows but not on MacOS ?

My package version are the same on both OS :
TypeScript 2.1.1
,
Webpack 1.13.3
, and modules have the exact same version with the help of the
yarn.lock
.

Here the
tsconfig.json
:

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"compileOnSave": false
}


Here the
webpack.config.js
:

var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: {
'app': [
'core-js/client/shim.min.js',
'zone.js/dist/zone',
'./src/app/main.ts'
]
},
output: {
path: './www',
filename: '[name].js'
},
module: {
loaders: [
{test: /\.component.ts$/, loader: 'ts!angular2-template'},
{test: /\.ts$/, exclude: /\.component.ts$/, loader: 'ts'},
{test: /\.html$/, loader: 'raw'}
]
},
resolve: {
extensions: ['', '.js', '.ts']
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
minimize: true
}),
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en-gb\.js|fr\.js/)
]
};


Here the beginning of
webpack
output (few lines because there are 10300 lines of error) :

ts-loader: Using typescript@2.1.1 and /Users/yolo/Documents/app1/tsconfig.json
Hash: 3b637fc56087f3ccacc8
Version: webpack 1.13.3
Time: 27898ms
Asset Size Chunks Chunk Names
app.js 915 kB 0 [emitted] app
index.html 1 kB [emitted]
[0] multi app 52 bytes {0} [built]
[27] ./src/app/app.module.js 4.55 kB {0} [built]
[33] ./src/app/request/request.service.js 3.19 kB {0} [built]
[34] ./src/app/system/system.js 269 bytes {0} [built]
[63] ./src/app/app.component.js 1.19 kB {0} [built]
[64] ./src/app/rxjs-operators.js 347 bytes {0} [built]
[85] ./src/app/app.routing.js 1.4 kB {0} [built]
[86] ./src/app/login/login.component.js 8.95 kB {0} [built]
[87] ./src/app/navbar/navbar.service.js 4.25 kB {0} [built]
[88] ./src/app/account/account.service.js 1.98 kB {0} [built]
[89] ./src/app/location/location.service.js 2.56 kB {0} [built]
[90] ./src/app/storage/storage.service.js 6.8 kB {0} [built]
[91] ./src/app/version/version.service.js 1.4 kB {0} [built]
[92] ./src/app/download/download.service.js 1.41 kB {0} [built]
[93] ./src/app/page-dialog/page-dialog.service.js 2.93 kB {0} [built]
[94] ./src/app/pages/pages.service.js 9.54 kB {0} [built]
[100] ./src/app/slideshow/slideshow.component.js 2.19 kB {0} [built]
[101] ./src/app/logout/logout.component.js 2.27 kB {0} [built]
[102] ./src/app/proceeded-pages/proceeded-pages.component.js 2.92 kB {0} [built]
[103] ./src/app/pages/pages.component.js 3.38 kB {0} [built]
[104] ./src/app/planning/planning.component.js 3.05 kB {0} [built]
[105] ./src/app/planning/planning.service.js 4.04 kB {0} [built]
[106] ./src/app/init/init.component.js 11.6 kB {0} [built]
[107] ./src/app/navbar/navbar.component.js 2.54 kB {0} [built]
[108] ./src/app/page/page.component.js 3.08 kB {0} [built]
[109] ./src/app/page/page.js 122 bytes {0} [built]
[110] ./src/app/login/login-form/login-form.component.js 2.87 kB {0} [built]
[111] ./src/app/login/login.js 203 bytes {0} [built]
[112] ./src/app/directives/c7z-container.directive.js 1.81 kB {0} [built]
[113] ./src/app/directives/c7z-full-height.directive.js 1.61 kB {0} [built]
[114] ./src/app/page-dialog/page-dialog.component.js 4.18 kB {0} [built]
+ 84 hidden modules

ERROR in /Users/yolo/Documents/app1/www/node_modules/zone.js/dist/zone.js.d.ts
(122,11): error TS2451: Cannot redeclare block-scoped variable 'Zone'.

ERROR in /Users/yolo/Documents/app1/www/node_modules/zone.js/dist/zone.js.d.ts
(367,14): error TS2300: Duplicate identifier 'HasTaskState'.

ERROR in /Users/yolo/Documents/app1/www/node_modules/zone.js/dist/zone.js.d.ts
(376,14): error TS2300: Duplicate identifier 'TaskType'.

ERROR in /Users/yolo/Documents/app1/www/node_modules/zone.js/dist/zone.js.d.ts
(462,15): error TS2451: Cannot redeclare block-scoped variable 'Zone'.

ERROR in /Users/yolo/Documents/app1/typings/globals/phonegap-plugin-push/index.d.ts
(4,7): error TS2300: Duplicate identifier 'EventResponse'.

ERROR in /Users/yolo/Documents/app1/typings/globals/phonegap-plugin-push/index.d.ts
(190,3): error TS2374: Duplicate string index signature.

ERROR in /Users/yolo/Documents/app1/typings/globals/phonegap-plugin-push/index.d.ts
(250,3): error TS2374: Duplicate string index signature.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(46,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'main' must be of type 'any', but here has type 'NodeModule'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(57,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'parent' must be of type 'any', but here has type 'NodeModule'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(58,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'children' must be of type 'any[]', but here has type 'NodeModule[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(78,6): error TS2300: Duplicate identifier 'BufferEncoding'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(227,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'errno' must be of type 'string', but here has type 'number'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(234,18): error TS2300: Duplicate identifier 'EventEmitter'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(522,26): error TS2300: Duplicate identifier 'Buffer'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(522,50): error TS2300: Duplicate identifier 'SlowBuffer'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(543,18): error TS2300: Duplicate identifier 'EventEmitter'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(543,18): error TS2415: Class 'EventEmitter' incorrectly extends base class 'NodeJS.EventEmitter'.
Types of property 'eventNames' are incompatible.
Type '() => (string | symbol)[]' is not assignable to type '() => string[]'.
Type '(string | symbol)[]' is not assignable to type 'string[]'.
Type 'string | symbol' is not assignable to type 'string'.
Type 'symbol' is not assignable to type 'string'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(654,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'httpVersionMajor' must be of type 'string', but here has type 'number'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(655,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'httpVersionMinor' must be of type 'string', but here has type 'number'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(656,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'connection' must be of type 'any', but here has type 'Socket'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(706,18): error TS2300: Duplicate identifier 'Agent'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(761,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'addressType' must be of type 'string', but here has type 'number | "udp4" | "udp6"'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(764,18): error TS2300: Duplicate identifier 'Worker'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(1485,18): error TS2300: Duplicate identifier 'Script'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2016,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'type' must be of type 'string', but here has type '"udp4" | "udp6"'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2432,22): error TS2451: Cannot redeclare block-scoped variable 'constants'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2787,18): error TS2300: Duplicate identifier 'TLSSocket'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2984,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'pfx' must be of type 'any', but here has type 'string | Buffer[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2985,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'key' must be of type 'any', but here has type 'string | any[] | string[] | Buffer'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2987,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'cert' must be of type 'any', but here has type 'string | string[] | Buffer | Buffer[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2988,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'ca' must be of type 'any', but here has type 'string | string[] | Buffer | Buffer[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2989,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'crl' must be of type 'any', but here has type 'string | string[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2991,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'honorCipherOrder' must be of type 'any', but here has type 'boolean'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(2994,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'NPNProtocols' must be of type 'any', but here has type 'string[] | Buffer'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(3011,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'key' must be of type 'string | Buffer', but here has type 'string | string[] | Buffer | Buffer[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(3013,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'cert' must be of type 'string | Buffer', but here has type 'string | string[] | Buffer | Buffer[]'.

ERROR in /Users/yolo/Documents/app1/typings/globals/node/index.d.ts
(3014,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'ca' must be of type '(string | Buffer)[]', but here has type 'string | Buffer | (string | Buffer)[]'.

Answer

I can't say with certainty because I need more of the error log file, but it seems that webpack is compiling typescript definitions from /node_modules as well as typings as well as your application. Since there are errors about duplicate identifiers, it leads me to think that some definitions are found in both node_modules and typings. You could try excluding node_modules definitions from being compiled and see if that makes a difference. To do so, add the following to tsconfig.json:

"compilerOptions": {
    ...
},
"exclude": [
    "node_modules"
]

Again, I cannot say for certain that this is the issue, it's more of a guess. Also, I am not sure why this would work on windows and not on Mac.