1
votes

I'm trying to setting up angular 2 with webpack 2 but I'm getting build errors.

I just imported @angular/platform-browser-dynamic But it is showing lot of errors on the screen. cannot find the module 'error cannot find name 'global'.' is one of those

ERROR in C:\Users\T12449\Desktop\angular\hello-angular\node_modules\zone.js\lib\zone-spec\wtf.ts (156,80): error TS2304: Cannot find name 'global'.

ERROR in C:\Users\T12449\Desktop\angular\hello-angular\node_modules\zone.js\lib\zone-spec\fake-async-test.ts (268,80): error TS2304: Cannot find name 'global'.

ERROR in C:\Users\T12449\Desktop\angular\hello-angular\node_modules\zone.js\lib\node\node.ts (18,93): error TS2304: Cannot find name 'global'.

My 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' }
   ]
 }
}

package.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"
]
}
1
This solution helped after spending some time online. https://stackoverflow.com/a/45446470/6736510Johnyoat

1 Answers

3
votes

Have you tried setting:

typings.d.ts   //If you don't see this file under src folder create one

With:

declare var global: any

As described here: https://github.com/angular/angular-cli#3rd-party-library-installation