shlomiassaf / ngc-webpack

Angular compiler-cli with webpack's loader chain.
MIT License
84 stars 15 forks source link

Pass compiler instead of compilation to findPlugin #34

Open dreef3 opened 7 years ago

dreef3 commented 7 years ago

Otherwise causes the following error, webpack@3:

Module build failed: TypeError: Cannot read property 'options' of undefined
    at Object.findPlugin (node_modules/ngc-webpack/src/webpack-wrapper.js:27:20)
    at Object.aotCleanLoader (node_modules/ngc-webpack/src/aot-clean-transformer/loader/text-based-loader/loader.js:184:44)
    at Object.aotCleanLoader (node_modules/ngc-webpack/src/aot-clean-transformer/loader/index.js:15:51)
dreef3 commented 7 years ago

@shlomiassaf It says An error occurred while generating the build script. on Travis, no idea how to fix this...

shlomiassaf commented 7 years ago

@dreef3 can you elaborate a bit more on the issue?

dreef3 commented 7 years ago

@shlomiassaf,

The comment above is the error from Travis CI, somehow the build doesn't start at all.

The issue that I'm trying to fix in this PR is reproduced with setup from README on webpack@3. It appears that loaders pass compilation instead of compiler object to function findPlugin. Compared with code in webpack-wrapper.js itself:

https://github.com/shlomiassaf/ngc-webpack/blob/master/src/webpack-wrapper.ts#L43 https://github.com/shlomiassaf/ngc-webpack/blob/master/src/aot-clean-transformer/loader/text-based-loader/loader.ts#L238

shlomiassaf commented 7 years ago

@dreef3 Something doesn't fit.

1) there's a Typescript change you did which is not related to webpack...

2) the project is based on webpack 2, you did not update the package.json files so it still runs on webpack 2 which ofcourse fails with changes for wabpack 3.

3) Webpack 2 is still widely used, a change must be backward compatible.

dreef3 commented 7 years ago
  1. It looks like ts.updateProperty accepts 7 arguments instead of 6 since typescript 2.5:
    function updateProperty(node: PropertyDeclaration, decorators: ReadonlyArray<Decorator> | undefined, modifiers: ReadonlyArray<Modifier> | undefined, name: string | PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): PropertyDeclaration;

    https://github.com/Microsoft/TypeScript/blob/v2.5.3/lib/typescript.d.ts#L3141

Maybe its better to add typescript <= 2.4 to peerDependencies instead.

  1. I checked Compilation source on 2.x branch and now I think that the change is backward compatible in the sense that the same bug should've appeared with webpack@2 too as there's no plugins property on Compilation: https://github.com/webpack/webpack/blob/v2.7.0/lib/Compilation.js#L50 https://github.com/webpack/webpack/blob/v3.8.1/lib/Compilation.js#L53

I'm not sure what causes the build in Travis to fail. There're no logs related to the project itself. I executed npm run ci locally and it passed (that's when I discovered p.1 above)

shlomiassaf commented 7 years ago

@dreef3 Due to changes in angular 5 i'v refactor the while library. There are no transformers anymore...