With Angular 13 update getting build issue with webpack4 and it's working fine in version 12
Which @angular/* package(s) are the source of the bug?
compiler-cli, compiler, upgrade
Is this a regression?
No
Description
Hi - I am using angular 12 and now trying to upgrade to version 13 after updating to version 13 (https://update.angular.io/?v=12.0-13.0) when I am building my app it's throwing error with below message. An unhandled exception occurred: Class extends value undefined is not a constructor or null See "C:\Users\z004dsas\AppData\Local\Temp\ng-7yn8fy\angular-errors.log" for further details.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
[error] TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (D:\Azure Workspace\CS-Cinematic-Anatomy\UI\node_modules\webpack-subresource-integrity\index.js:38:49)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (D:\Azure Workspace\CS-Cinematic-Anatomy\UI\node_modules\@angular-devkit\build-angular\src\webpack\configs\common.js:38:41)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 13.2.2
Node: 14.16.1
Package Manager: npm 6.14.12
OS: win32 x64
Angular: 13.2.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1302.2
@angular-devkit/build-angular 13.2.2
@angular-devkit/core 13.2.2
@angular-devkit/schematics 13.2.2
@angular/cli 13.2.2
@schematics/angular 13.2.2
rxjs 6.5.5
typescript 4.4.2
webpack 4.42.0
Anything else?
My webpack.config.js file
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const config = require('./package.json').config;
const webpack = require('webpack');
module.exports = (env) => {
const webpackConfig = {
target: 'node',
entry: ${config.electronMainRootPath}main.ts,
node: {
__dirname: false
},
module: {
rules: [
{
test: /.ts$/,
loaders: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
sourceMap: !env || !env.production,
declaration: false,
moduleResolution: 'node',
emitDecoratorMetadata: true,
experimentalDecorators: true,
target: 'es2015',
lib: ['es2017', 'es2016', 'es2015', 'dom']
},
onlyCompileBundledFiles: true
}
}
]
}
]
},
resolve: {
extensions: ['.ts'],
plugins: [new TsconfigPathsPlugin()]
},
externals: [nodeExternals()]
};
if (env && env.production) { webpackConfig.mode = 'production';
webpackConfig.output = {
path: path.resolve(__dirname, 'dist'),
filename: 'electron-main.min.js'
};
webpackConfig.optimization = {
minimizer: [
new TerserWebpackPlugin({
terserOptions: {
compress: {
drop_console: true
}
}
})
]
};
if (!webpackConfig.plugins) {
webpackConfig.plugins = [];
}
if (env.conf) {
// Replace config with config.prod file
webpackConfig.plugins.push(
new webpack.NormalModuleReplacementPlugin(/(.*)configuration\/config(\.*)/, function (resource) {
resource.request = resource.request.replace(/configuration\/config/, `configuration/config.${env.conf}`);
})
);
}
}else {
webpackConfig.mode = 'development';
webpackConfig.devtool = 'inline-source-map';
webpackConfig.output = {
path: path.resolve(__dirname),
filename: electron-main.dev.js
};
}
return webpackConfig; };
Hi @Avinash4243,
Custom webpack configurations are not supported by the Angular team. If the problem persists using the Angular CLI directly. please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. You can use ng new repro-app to create a new project where you reproduce the problem.
@alan-agius4 Hi. Thank you for your response. That webpack.config is for my node setup not Angular.
I have the same issue. Running fine in V12. After upgrading to V13, get error when running ng serve: An unhandled exception occurred: Class extends value undefined is not a constructor or null See "C:\Users\jweng\AppData\Local\Temp\ng-wd6Swk\angular-errors.log" for further details.
The error log:
[error] TypeError: Class extends value undefined is not a constructor or null
at Object.
Same here going from v12 to v13 (I bet its a circular dependency that angular 12 was lenient in but with optimisations in 13 it is now barfing).
[error] TypeError: Class extends value undefined is not a constructor or null
at Object.
We fixed the problem by changing webpack version in package.json from 4.44.1 => "webpack": "^5.70.0"
Yes, I fixed the circular dependencies and still facing the same error. I used madge to check circular dependency.
@polaroffer try changing webpack version in package.json from 4.44.1 => "webpack": "^5.70.0"
This is the index.js where the error is thrown: (line 38 is : class AddLazySriRuntimeModule extends webpack_1.RuntimeModule {
index.js content: "use strict"; /**
- Copyright (c) 2015-present, Waysact Pty Ltd *
- This source code is licensed under the MIT license found in the
- LICENSE file in the root directory of this source tree.
/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubresourceIntegrityPlugin = void 0;
const crypto_1 = require("crypto");
const webpack_1 = require("webpack");
const plugin_1 = require("./plugin");
const reporter_1 = require("./reporter");
const util_1 = require("./util");
const thisPluginName = "webpack-subresource-integrity";
// https://www.w3.org/TR/2016/REC-SRI-20160623/#cryptographic-hash-functions
const standardHashFuncNames = ["sha256", "sha384", "sha512"];
let getHtmlWebpackPluginHooks = null;
class AddLazySriRuntimeModule extends webpack_1.RuntimeModule {
constructor(sriHashes, chunkName) {
super(
webpack-subresource-integrity lazy hashes for direct children of chunk ${chunkName}); this.sriHashes = sriHashes; } generate() { return webpack_1.Template.asString([Object.assign(${util_1.sriHashVariableReference}, ${JSON.stringify(this.sriHashes)});, ]); } } /* - The webpack-subresource-integrity plugin. *
- @public
/
class SubresourceIntegrityPlugin {
/*
- Create a new instance. *
- @public
/
constructor(options = {}) {
/*
- @internal
/
this.setup = (compilation) => {
const reporter = new reporter_1.Reporter(compilation, thisPluginName);
if (!this.validateOptions(compilation, reporter) ||
!this.isEnabled(compilation)) {
return;
}
const plugin = new plugin_1.Plugin(compilation, this.options, reporter);
if (typeof compilation.outputOptions.chunkLoading === "string" &&
["require", "async-node"].includes(compilation.outputOptions.chunkLoading)) {
reporter.warnOnce("This plugin is not useful for non-web targets.");
return;
}
compilation.hooks.beforeRuntimeRequirements.tap(thisPluginName, () => {
plugin.beforeRuntimeRequirements();
});
compilation.hooks.processAssets.tap({
name: thisPluginName,
stage: compilation.compiler.webpack.Compilation
.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
}, (records) => {
return plugin.processAssets(records);
});
compilation.hooks.afterProcessAssets.tap(thisPluginName, (records) => {
for (const chunk of compilation.chunks.values()) {
for (const chunkFile of chunk.files) {
if (chunkFile in records &&
records[chunkFile].source().includes(util_1.placeholderPrefix)) {
reporter.errorOnce(
Asset ${chunkFile} contains unresolved integrity placeholders); } } } }); compilation.compiler.webpack.optimize.RealContentHashPlugin.getCompilationHooks(compilation).updateHash.tap(thisPluginName, (input, oldHash) => { // FIXME: remove type hack pending https://github.com/webpack/webpack/pull/12642#issuecomment-784744910 return plugin.updateHash(input, oldHash); }); if (getHtmlWebpackPluginHooks) { getHtmlWebpackPluginHooks(compilation).beforeAssetTagGeneration.tapPromise(thisPluginName, async (pluginArgs) => { plugin.handleHwpPluginArgs(pluginArgs); return pluginArgs; }); getHtmlWebpackPluginHooks(compilation).alterAssetTagGroups.tapPromise({ name: thisPluginName, stage: 10000, }, async (data) => { plugin.handleHwpBodyTags(data); return data; }); } const { mainTemplate } = compilation; mainTemplate.hooks.jsonpScript.tap(thisPluginName, (source) => plugin.addAttribute("script", source)); mainTemplate.hooks.linkPreload.tap(thisPluginName, (source) => plugin.addAttribute("link", source)); mainTemplate.hooks.localVars.tap(thisPluginName, (source, chunk) => { const allChunks = this.options.hashLoading === "lazy" ? plugin.getChildChunksToAddToChunkManifest(chunk) : util_1.findChunks(chunk); const includedChunks = chunk.getChunkMaps(false).hash; if (Object.keys(includedChunks).length > 0) { return compilation.compiler.webpack.Template.asString([ source,${util_1.sriHashVariableReference} =+ JSON.stringify(util_1.generateSriHashPlaceholders(Array.from(allChunks).filter((depChunk) => depChunk.id !== null && includedChunks[depChunk.id.toString()]), this.options.hashFuncNames)) + ";", ]); } return source; }); if (this.options.hashLoading === "lazy") { compilation.hooks.additionalChunkRuntimeRequirements.tap(thisPluginName, (chunk) => { var _a; const childChunks = plugin.getChildChunksToAddToChunkManifest(chunk); if (childChunks.size > 0 && !chunk.hasRuntime()) { compilation.addRuntimeModule(chunk, new AddLazySriRuntimeModule(util_1.generateSriHashPlaceholders(childChunks, this.options.hashFuncNames), (_a = chunk.name) !== null && _a !== void 0 ? _a : chunk.id)); } }); } }; /* - @internal / this.validateOptions = (compilation, reporter) => { if (this.isEnabled(compilation) && !compilation.compiler.options.output.crossOriginLoading) { reporter.warnOnce('SRI requires a cross-origin policy, defaulting to "anonymous". ' + "Set webpack option output.crossOriginLoading to a value other than false " + "to make this warning go away. " + "See https://w3c.github.io/webappsec-subresource-integrity/#cross-origin-data-leakage"); } return (this.validateHashFuncNames(reporter) && this.validateHashLoading(reporter)); }; /*
- @internal / this.validateHashFuncNames = (reporter) => { if (!Array.isArray(this.options.hashFuncNames)) { reporter.error("options.hashFuncNames must be an array of hash function names, " + "instead got '" + this.options.hashFuncNames + "'."); return false; } else if (this.options.hashFuncNames.length === 0) { reporter.error("Must specify at least one hash function name."); return false; } else if (!this.options.hashFuncNames.every(this.validateHashFuncName.bind(this, reporter))) { return false; } else { this.warnStandardHashFunc(reporter); return true; } }; /*
- @internal
/
this.validateHashLoading = (reporter) => {
const supportedHashLoadingOptions = Object.freeze(["eager", "lazy"]);
if (supportedHashLoadingOptions.includes(this.options.hashLoading)) {
return true;
}
const optionsStr = supportedHashLoadingOptions
.map((opt) =>
'${opt}') .join(", "); reporter.error(options.hashLoading must be one of ${optionsStr}, instead got '${this.options.hashLoading}'); return false; }; /* - @internal / this.warnStandardHashFunc = (reporter) => { let foundStandardHashFunc = false; for (let i = 0; i < this.options.hashFuncNames.length; i += 1) { if (standardHashFuncNames.indexOf(this.options.hashFuncNames[i]) >= 0) { foundStandardHashFunc = true; } } if (!foundStandardHashFunc) { reporter.warnOnce("It is recommended that at least one hash function is part of the set " + "for which support is mandated by the specification. " + "These are: " + standardHashFuncNames.join(", ") + ". " + "See http://www.w3.org/TR/SRI/#cryptographic-hash-functions for more information."); } }; /*
- @internal / this.validateHashFuncName = (reporter, hashFuncName) => { if (typeof hashFuncName !== "string" && !(hashFuncName instanceof String)) { reporter.error("options.hashFuncNames must be an array of hash function names, " + "but contained " + hashFuncName + "."); return false; } try { crypto_1.createHash(hashFuncName); } catch (error) { reporter.error("Cannot use hash function '" + hashFuncName + "': " + error.message); return false; } return true; }; if (typeof options !== "object") { throw new Error("webpack-subresource-integrity: argument must be an object"); } this.options = { hashFuncNames: ["sha384"], enabled: "auto", hashLoading: "eager", ...options, }; } /*
- @internal
/
this.setup = (compilation) => {
const reporter = new reporter_1.Reporter(compilation, thisPluginName);
if (!this.validateOptions(compilation, reporter) ||
!this.isEnabled(compilation)) {
return;
}
const plugin = new plugin_1.Plugin(compilation, this.options, reporter);
if (typeof compilation.outputOptions.chunkLoading === "string" &&
["require", "async-node"].includes(compilation.outputOptions.chunkLoading)) {
reporter.warnOnce("This plugin is not useful for non-web targets.");
return;
}
compilation.hooks.beforeRuntimeRequirements.tap(thisPluginName, () => {
plugin.beforeRuntimeRequirements();
});
compilation.hooks.processAssets.tap({
name: thisPluginName,
stage: compilation.compiler.webpack.Compilation
.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
}, (records) => {
return plugin.processAssets(records);
});
compilation.hooks.afterProcessAssets.tap(thisPluginName, (records) => {
for (const chunk of compilation.chunks.values()) {
for (const chunkFile of chunk.files) {
if (chunkFile in records &&
records[chunkFile].source().includes(util_1.placeholderPrefix)) {
reporter.errorOnce(
- @internal */ isEnabled(compilation) { if (this.options.enabled === "auto") { return compilation.options.mode !== "development"; } return this.options.enabled; } apply(compiler) { compiler.hooks.beforeCompile.tapPromise(thisPluginName, async () => { try { getHtmlWebpackPluginHooks = (await Promise.resolve().then(() => __importStar(require("html-webpack-plugin")))) .default.getHooks; } catch (e) { if (e.code !== "MODULE_NOT_FOUND") { throw e; } } }); compiler.hooks.afterPlugins.tap(thisPluginName, (compiler) => { compiler.hooks.thisCompilation.tap({ name: thisPluginName, stage: -10000, }, (compilation) => { this.setup(compilation); }); compiler.hooks.compilation.tap(thisPluginName, (compilation) => { compilation.hooks.statsFactory.tap(thisPluginName, (statsFactory) => { statsFactory.hooks.extract .for("asset") .tap(thisPluginName, (object, asset) => { var _a; const contenthash = (_a = asset.info) === null || _a === void 0 ? void 0 : _a.contenthash; if (contenthash) { const shaHashes = (Array.isArray(contenthash) ? contenthash : [contenthash]).filter((hash) => String(hash).match(/^sha[0-9]+-/)); if (shaHashes.length > 0) { object.integrity = shaHashes.join(" "); } } }); }); }); }); } } exports.SubresourceIntegrityPlugin = SubresourceIntegrityPlugin; //# sourceMappingURL=index.js.map
to prove your webpack isn't importing you can edit the index.js around line 38 and put console.error("do we have a webpack", webpack_1); Do it after the line const webpack_1 = require("webpack");
@pjcoupe Thank you very much for the hint. Change the webpack version works!
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.