s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 179 forks source link

[3.0.0-beta.3] TypeError: Cannot read property 'forEach' of undefined #277

Closed ocombe closed 7 years ago

ocombe commented 7 years ago

With this version I get this error with some of my imports (it was working fine with v2.x). The complete error message is:

ERROR in ./src/polyfills.ts
Module build failed: TypeError: Cannot read property 'forEach' of undefined
    at C:\www\front-portal-v2\node_modules\awesome-typescript-loader\src\index.ts:81:27
    at process._tickCallback (internal/process/next_tick.js:103:7)
 @ multi polyfills

The import that causes problem is:

import 'classlist.js';

The library in question is: https://github.com/eligrey/classList.js/

And the corresponding error comes from:

transformation
        .then(trans => {
            if (!instance.compilerConfig.options.isolatedModules) {
                // If our modules are isolated we don't need to recompile all the deps
                trans.deps.forEach(dep => loader.addDependency(dep));  // <---- HERE
            }
//  [...]
dmeenhuis commented 7 years ago

Yeah I ran into the same issue when I tried running TypeScript@next in my project. I was able to temporarily solve it by monkey patching the corresponding file by initialising the trans.deps property to an empty array, but yeah, not exactly a very permanent solution :)

ocombe commented 7 years ago

I've tried with typescript 2.1.x and 2.0.8 and both fail, so the problem lies within ATL unfortunately :) I wish I could use beta 3 because it's much faster than 2.x

dmeenhuis commented 7 years ago

Yes, that appears to be the case. I didn't mean to imply the issue was just with TypeScript@next, that was just the setup I was testing :) I wish I could use @next since I'd really like to use TypeScript@next and I can't seem to get that to work with 2.x.

s-panferov commented 7 years ago

Can't reproduce this :-( Could you please provide your versions and tsconfig.json?

ocombe commented 7 years ago

Sure,

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES5",
    "lib": ["es5", "dom"],
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitThis": false,
    "sourceMap": true,
    "noEmitHelpers": true,
    "strictNullChecks": false,
    "allowJs": true,
    "skipDefaultLibCheck": true,
    "skipLibCheck": true,
    "pretty": true,
    "forceConsistentCasingInFileNames": true,
    "allowSyntheticDefaultImports": true
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "exclude": [
    "node_modules",
    "src/public/assets",
    "vendor"
  ],
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": false,
    "useCache": true,
    "useWebpackText": true,
    "ignoreDiagnostics": [2300]
  }
}

package.json:

{
  "scripts": {
    "build": "webpack --env.env build --progress --profile --bail",
    "start": "webpack-dev-server --env.env dev --progress --inline --hot --https --port=9001 --host=0.0.0.0 --watch"
  },
  "dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/router": "3.2.1",
    "@angularclass/hmr-loader": "3.0.2",
    "angular2-cookie": "1.2.5",
    "angular2-data-table": "1.7.0",
    "bootstrap": "4.0.0-alpha.4",
    "classlist.js": "1.1.20150312",
    "clipboard-js": "0.3.1",
    "core-js": "2.4.1",
    "d3": "4.3.0",
    "d3-selection-multi": "1.0.0",
    "flatpickr": "2.0.0",
    "lodash": "4.17.2",
    "moment": "2.16.0",
    "ng2-translate": "4.0.1",
    "popper.js": "0.6.4",
    "raven-js": "3.8.1",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "0.6.26"
  },
  "devDependencies": {
    "@angularclass/hmr": "1.2.2",
    "@angularclass/hmr-loader": "3.0.2",
    "@types/core-js": "0.9.34",
    "@types/d3": "4.3.0",
    "@types/d3-selection-multi": "1.0.3",
    "@types/hammerjs": "2.0.33",
    "@types/jasmine": "2.5.38",
    "@types/node": "6.0.48",
    "@types/protractor": "4.0.0",
    "@types/selenium-webdriver": "2.53.35",
    "@types/source-map": "0.5.0",
    "@types/uglify-js": "2.6.28",
    "@types/webpack": "2.0.0",
    "angular2-template-loader": "0.6.0",
    "autoprefixer": "6.5.3",
    "awesome-typescript-loader": "2.2.4",
    "clean-webpack-plugin": "0.1.14",
    "codelyzer": "1.0.0-beta.4",
    "commitizen": "2.8.6",
    "copy-webpack-plugin": "4.0.1",
    "css-loader": "0.25.0",
    "cz-conventional-changelog": "1.2.0",
    "extract-text-webpack-plugin": "2.0.0-beta.4",
    "file-loader": "0.9.0",
    "html-loader": "0.4.4",
    "html-webpack-plugin": "2.24.1",
    "istanbul-instrumenter-loader": "0.2.0",
    "jasmine-core": "2.5.2",
    "json-loader": "0.5.4",
    "karma": "1.3.0",
    "karma-chrome-launcher": "2.0.0",
    "karma-coverage": "1.1.1",
    "karma-jasmine": "1.0.2",
    "karma-mocha-reporter": "2.2.1",
    "karma-remap-coverage": "0.1.2",
    "karma-sourcemap-loader": "0.3.7",
    "karma-webpack": "1.8.0",
    "last-release-git": "0.0.2",
    "node-sass": "3.13.0",
    "null-loader": "0.1.1",
    "postcss-loader": "1.1.1",
    "raw-loader": "0.5.1",
    "remap-istanbul": "0.7.0",
    "sass-loader": "4.0.2",
    "semantic-release": "6.3.2",
    "shrinkpack": "0.17.1",
    "source-map-loader": "0.1.5",
    "style-loader": "0.13.1",
    "stylelint": "7.5.0",
    "stylelint-scss": "1.3.4",
    "stylelint-webpack-plugin": "0.4.0",
    "ts-helpers": "1.1.2",
    "tslint": "3.15.1",
    "tslint-loader": "2.1.5",
    "typescript": "2.1.1",
    "url-loader": "0.5.7",
    "webpack": "2.1.0-beta.26",
    "webpack-dev-server": "2.1.0-beta.11",
    "webpack-notifier": "1.4.1"
  },
  "postcss": {
    "plugins": {
      "autoprefixer": {
        "browsers": [
          "last 2 version"
        ]
      }
    }
  }
}

Just change the ATL version to beta 3.

Do you need my webpack config as well?

s-panferov commented 7 years ago

@ocombe is your source code open?

ocombe commented 7 years ago

unfortunately no, I would have linked to it otherwise :(

s-panferov commented 7 years ago

@ocombe ok, could you please also provide your nodejs version?

ocombe commented 7 years ago

node 7.0.0, npm 3.10.8, windows 10 x64

s-panferov commented 7 years ago

Could you please check 3.0.0-beta.4?

ocombe commented 7 years ago

Still the same with beta 4 :( I'll try to make you a minimal reproduction repo that you can use

dmeenhuis commented 7 years ago

I did some testing here locally, since I also ran into the same problem. I was able to resolve the issue by removing the local .awcache directory. Maybe there was a remnant in there from the previous version that was causing a conflict with the new 3. version. Perhaps that resolves your issue as well?

s-panferov commented 7 years ago

@ocombe does cleanup help?

ocombe commented 7 years ago

Looks like it helps. It was stopping really fast (at like 10% of the build) with those errors messages that I listed and now it goes way further, but it stops at some point (without any error message, it just stops at x%). It went to 67% the first time, then 33%, then 54%.

For example here it stopped at 33% and the shell's output is:

Project is running at http://localhost:8080/
webpack output is served from http://localhost:8080/
Content not from webpack is served from ./src/public
404s will fallback to /index.html

 10% building modules 5/11 modules 6 active ...dules\webpack\hot\log-apply-result.js
[at-loader] Using typescript@2.1.1 from typescript and "tsconfig.json" from C:\www\front-portal-v2/tsconfig.json

 33% building modules 324/824 modules 500 active ...ode_modules\rxjs\symbol\observable.js

And it doesn't do anything anymore. The node processes don't even use resources (proc usage is at 0%).

Here it stopped at 65%:

65% building modules 1284/1382 modules 98 active ...ww\front-portal-v2\src\style\app.scss

I'll let it run for a while to see if it ends up working or not.

s-panferov commented 7 years ago

"Cannot read property 'forEach' of undefined" issue was resolved.

Closing this in favour of #279

ocombe commented 7 years ago

Yes, thanks :)

robgha01 commented 7 years ago

@dmeenhuis Yes that was it... i could not find way this error was throwing almost lost my presus hair, thanck you so much! however should this really happen cant the cache be cleared somehow or add this info in the documentation for upgrade so people dont have to dig for gold or is it already existing @s-panferov ?