From 50699789d66b0fa465c794917451af1240c370e2 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 11 Jul 2023 16:23:05 +0200 Subject: [PATCH] Merge pull request #23405 from storybookjs/valentin/fix-esm-issue-in-angular Angular: Fix esm issue in combination with rxjs v6 (cherry picked from commit 2535f027e8116d540f56d74495d09ce242704267) --- .../angular/src/server/framework-preset-angular-ivy.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts b/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts index 987df7f78005..91f9eb31c110 100644 --- a/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts +++ b/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts @@ -1,6 +1,7 @@ import { Configuration } from 'webpack'; import * as path from 'path'; import { Preset } from '@storybook/types'; +import fs from 'fs'; import { PresetOptions } from './preset-options'; import { AngularOptions } from '../types'; @@ -49,10 +50,13 @@ export const runNgcc = async () => { }; export const webpack = async (webpackConfig: Configuration, options: PresetOptions) => { - const { VERSION } = await loadEsmModule('@angular/core'); + const packageJsonPath = require.resolve('@angular/core/package.json'); + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + const VERSION = packageJson.version; const framework = await options.presets.apply('framework'); const angularOptions = (typeof framework === 'object' ? framework.options : {}) as AngularOptions; - const isAngular16OrNewer = parseInt(VERSION.major, 10) >= 16; + const angularMajorVersion = VERSION.split('.')[0]; + const isAngular16OrNewer = parseInt(angularMajorVersion, 10) >= 16; // Default to true, if undefined if (angularOptions.enableIvy === false) {