pirelenito / git-revision-webpack-plugin

🏗 Webpack plugin that generates VERSION and COMMITHASH files during build
https://www.npmjs.com/package/git-revision-webpack-plugin
MIT License
358 stars 48 forks source link

Plugin triggers error with Angular 12 AngularWebpackPlugin #69

Closed dpraul closed 3 years ago

dpraul commented 3 years ago

Hello! I'm transitioning an application from Angular 11 to 12 and the build fails when utilizing this plugin alongside the AngularWebpackPlugin.

The following error is raised during compilation:

/app/node_modules/@ngtools/webpack/src/resource_loader.js:207
                            throw new Error(`'${name}' asset info 'sourceFilename' is 'undefined'.`);
                            ^

Error: 'COMMITHASH' asset info 'sourceFilename' is 'undefined'.
    at /app/node_modules/@ngtools/webpack/src/resource_loader.js:207:35
    at /app/node_modules/webpack/lib/Compiler.js:538:11
    at /app/node_modules/webpack/lib/Compiler.js:1106:17
    at Hook.eval [as callAsync] (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/app/node_modules/tapable/lib/Hook.js:18:14)
    at /app/node_modules/webpack/lib/Compiler.js:1102:33
    at finalCallback (/app/node_modules/webpack/lib/Compilation.js:2249:11)
    at /app/node_modules/webpack/lib/Compilation.js:2540:11
    at Hook.eval [as callAsync] (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/app/node_modules/tapable/lib/Hook.js:18:14)

Here is the line in question in the AngularWebpackPlugin: https://github.com/angular/angular-cli/blob/736a5f89deaca85f487b78aec9ff66d4118ceb6a/packages/ngtools/webpack/src/resource_loader.ts#L279-L284

The build completes successfully if I rewrite line 280 of the previous source to the following line:

if (info.sourceFilename === undefined && !['VERSION', 'COMMITHASH', 'LASTCOMMITDATETIME', 'BRANCH'].includes(name)) {

I'm not certain if the check in the AngularWebpackPlugin should be adjusted or if extra information needs to be attached to the assets produced from this plugin, but figured I'd start with raising the issue here.

pirelenito commented 3 years ago

Hello!

From Webpack's type definitions we can see that the sourceFilename is an optional value:

/**
 * when asset was created from a source file (potentially transformed), the original filename relative to compilation context
 */
sourceFilename?: string;

Given git-revision-webpack-plugin generates these assets not from a source file, I would say that the issue in in the Angular plugin.

I'll close this issue, but feel free to re-open if I'm mistaken or if you have new information.

Cheers 👋