Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 12 Support #14909

Closed
gaetanmaisse opened this issue May 13, 2021 · 81 comments
Closed

Angular 12 Support #14909

gaetanmaisse opened this issue May 13, 2021 · 81 comments

Comments

@gaetanmaisse
Copy link
Member

gaetanmaisse commented May 13, 2021

Describe

Angular 12 was released a few hours ago, release post, and it looks like Storybook isn't working with it out of the box for now.

When running yarn storybook, it throws the following error:

info @storybook/angular v6.3.0-alpha.25
info
info => Loading presets
info => Loading 1 config file in "/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/.storybook"
info => Loading 7 other files in "/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/.storybook"
info => Adding stories defined in "/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/.storybook/main.js"
info => Found custom tsconfig.json
info => Using implicit CSS loaders
info => Cleared cached manager config
ℹ 「wdm」: wait until bundle finished:
info => Loading angular-cli config
info => Using angular project "angular" for configuring Storybook
info => Using angular-cli webpack config
info => Using default Webpack4 setup
ERR! WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules[9] has an unknown property 'mimetype'. These properties are valid:
ERR!    object { compiler?, enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, realResource?, resolve?, resource?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }
ERR!    -> A rule
ERR!     at Object.webpack [as get] (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/webpack.js:31:9)
ERR!     at Object.start (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:92:27)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/core-server/dist/cjs/dev-server.js:114:28)
ERR!     at async buildDevStandalone (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/core-server/dist/cjs/build-dev.js:109:31)
ERR!     at async Object.buildDev (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/core-server/dist/cjs/build-dev.js:150:5)
ERR!  WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules[9] has an unknown property 'mimetype'. These properties are valid:
ERR!    object { compiler?, enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, realResource?, resolve?, resource?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }
ERR!    -> A rule
ERR!     at Object.webpack [as get] (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/webpack.js:31:9)
ERR!     at Object.start (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:92:27)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/core-server/dist/cjs/dev-server.js:114:28)
ERR!     at async buildDevStandalone (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/core-server/dist/cjs/build-dev.js:109:31)
ERR!     at async Object.buildDev (/private/var/folders/vz/y7q44gbj4ks8ykwqgh8qgxxc0000gn/T/tmp.svpVK5CL/angular/node_modules/@storybook/core-server/dist/cjs/build-dev.js:150:5)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

To Reproduce

To bootstrap a fresh Angular 12 + Storybook 6.3 alpha just run npx sb@next repro ./a_directory --framework angular --template angular

System

  System:
    OS: macOS 11.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node
    Yarn: 2.4.1 - /usr/local/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm
  Browsers:
    Chrome: 90.0.4430.212
    Firefox: 87.0
    Safari: 14.1
  npmPackages:
    @storybook/addon-actions: ^6.3.0-alpha.25 => 6.3.0-alpha.25
    @storybook/addon-docs: ^6.3.0-alpha.25 => 6.3.0-alpha.25
    @storybook/addon-essentials: ^6.3.0-alpha.25 => 6.3.0-alpha.25
    @storybook/addon-links: ^6.3.0-alpha.25 => 6.3.0-alpha.25
    @storybook/angular: ^6.3.0-alpha.25 => 6.3.0-alpha.25

    @angular-devkit/build-angular: ~12.0.0
    @angular/cli: ~12.0.0
    @angular/compiler-cli: ~12.0.0

Additional context

Maybe also related to #14044 (comment)?

@shilman
Copy link
Member

shilman commented May 13, 2021

When I run npx sb@next init --builder webpack5 I get the following error at startup, which seems to match #13893 (comment):

10% building 0/1 entries 0/0 dependencies 0/0 modulesℹ 「wdm」: wait until bundle finished:
/Users/shilman/projects/testing/ng12-app/node_modules/webpack/lib/util/MapHelpers.js:17
	const value = map.get(key);
	                  ^

TypeError: Cannot read property 'get' of undefined
    at exports.provide (/Users/shilman/projects/testing/ng12-app/node_modules/webpack/lib/util/MapHelpers.js:17:20)
    at /Users/shilman/projects/testing/ng12-app/node_modules/webpack/lib/DefinePlugin.js:289:51
    at SyncHook.eval [as call] (eval at create (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
    at SyncHook.lazyCompileHook (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.newCompilation (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/webpack/lib/Compiler.js:631:26)
    at /Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/webpack/lib/Compiler.js:667:29
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.compile (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/webpack/lib/Compiler.js:662:28)
    at /Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/webpack/lib/Watching.js:77:18
    at _next0 (eval at create (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:25:1)
    at eval (eval at create (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:34:1)
    at watchRunHook (/Users/shilman/projects/testing/ng12-app/node_modules/webpack-virtual-modules/index.js:173:5)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:30:1)
    at AsyncSeriesHook.lazyCompileHook (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/tapable/lib/Hook.js:154:20)
    at Watching._go (/Users/shilman/projects/testing/ng12-app/node_modules/@storybook/core-server/node_modules/webpack/lib/Watching.js:41:32)
error Command failed with exit code 1.

@shilman shilman added P1 and removed needs triage labels May 13, 2021
@ThibaudAV ThibaudAV self-assigned this May 13, 2021
@bebraw
Copy link
Contributor

bebraw commented May 13, 2021

Here's what I did:

  1. npx sb@next repro angular-demo --framework angular --template angular
  2. npx sb@next init --builder webpack5 within the angular-demo directory that was created
  3. yarn storybook

And here are the errors I received: https://gist.github.com/bebraw/c36e1d0c6067e9409346928630e0e58c . Examples: ModuleNotFoundError: Module not found: Error: Can't resolve '@webcomponents/custom-elements', ModuleNotFoundError: Module not found: Error: Can't resolve '@webcomponents/custom-elements/src/native-shim' in ....

I wonder if something has changed since @shilman's go at it. It's possible the builder was updated for example and how there are new problems to solve.

@shilman
Copy link
Member

shilman commented May 13, 2021

Thanks @bebraw. I'm not sure what's different between your setup and mine.

I followed your steps (with a --force after the second step), and then did a couple more steps to git it working:

npx sb@next repro angular-repro -t angular
cd angular-repro
npx sb@next init --builder webpack5 --force
# add missing dependencies
yarn add -D @angular/elements @webcomponents/custom-elements

Then I manually added this to .storybook/main.js:

module.exports = {
  // stories, addons, etc...
  webpackFinal: async (config) => {
    if (!config.resolve.fallback) {
      config.resolve.fallback = {};
    }
    config.resolve.fallback.crypto = false;
    return config;
  },
};

And it's working! 🎉

What I think needs to happen:

  • add @angular/elements @webcomponents/custom-elements as extraDependencies in the CLI init for angular
  • set the docs.inlineStories parameter to true in the CLI by default while we're at it
  • possibly make that webpack code automatically part of builder-webpack5. i got the fix from here: Addon-a11y: Fix crypto in webpack5 #14592

I'm not sure this will handle all the cases, but at least it handles one. @ThibaudAV @bebraw @ndelangen WDYT?

@bebraw
Copy link
Contributor

bebraw commented May 13, 2021

@shilman It makes sense to me that the webpack 5 builder owns the related configuration customization. Also it sounds reasonable the missing dependencies are added at CLI init so the users don't have to add them manually as it's confusing to fix otherwise.

@shilman
Copy link
Member

shilman commented May 13, 2021

@bebraw Yeah I think those are optional dependencies but the behavior changed in yarn 2. Thanks for taking a look at this!! 🙏

@ThibaudAV
Copy link
Contributor

arf

@ThibaudAV
Copy link
Contributor

ThibaudAV commented May 13, 2021

i juste read this

new webpack.IgnorePlugin({ resourceRegExp, contextRegExp });
// Supported in webpack 4 and earlier, unsupported in webpack 5:
new webpack.IgnorePlugin(resourceRegExp, [contextRegExp]);

So if we change this line with :

return [new IgnorePlugin({ resourceRegExp: /@storybook(\\|\/)angular(\\|\/)element-renderer/ })];

it works perfectly again 😀 (tested with an edit in cjs quickly)

@literalpie
Copy link
Contributor

literalpie commented May 13, 2021

The fix discussed above works in my minimal reproduction repo, but I am still getting an error with sass-loader when the manager is built/run in our real-world usage of storybook.
image
I'm still trying to narrow down the exact cause

edit: this was caused by us using this to load styles in the manager: require('!style-loader!css-loader!sass-loader!./manager-styles.scss');. This is a problem because the sass-loader installed only works with webpack 5. We fixed this by installing a webpack 4 compatible version of the manager (in package.json): "sass-loader-webpack4": "npm:sass-loader@10.1.1". I'm assuming all this we're doing is unsupported, but maybe it'll be helpful to someone.

Unfortunately, we are still having other issues

@bebraw
Copy link
Contributor

bebraw commented May 13, 2021 via email

@shilman
Copy link
Member

shilman commented May 14, 2021

Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-alpha.27 containing PR #14928 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed May 14, 2021
@eugene-stativka
Copy link

Hi @shilman! Thank you for 6.3.0-alpha.27 release. Unfortunately, it did not help me to fix my error. It tried both upgrade and setup from the beginning. The same error:

info @storybook/angular v6.3.0-alpha.27
info 
info => Loading presets
info => Loading 1 config file in "/my-project/.storybook"
info => Loading 7 other files in "/my-project/.storybook"
info => Using prebuilt manager
info => Adding stories defined in "/my-project/.storybook/main.js"
info => Found custom tsconfig.json
info => Using implicit CSS loaders
info => Loading angular-cli config
info => Using angular project "my-project" for configuring Storybook
ERR! => Could not get angular cli webpack config
ERR! TypeError: Cannot read property 'minify' of undefined
ERR!     at getCommonConfig (/my-project/node_modules/@angular-devkit/build-angular/src/webpack/configs/common.js:237:28)
ERR!     at Object.<anonymous> (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:199:39)
ERR!     at step (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:69:23)
ERR!     at Object.next (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:50:53)
ERR!     at fulfilled (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:41:58)
ERR!  TypeError: Cannot read property 'minify' of undefined
ERR!     at getCommonConfig (/my-project/node_modules/@angular-devkit/build-angular/src/webpack/configs/common.js:237:28)
ERR!     at Object.<anonymous> (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:199:39)
ERR!     at step (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:69:23)
ERR!     at Object.next (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:50:53)
ERR!     at fulfilled (/my-project/node_modules/@storybook/angular/dist/ts3.9/server/angular-devkit-build-webpack.js:41:58)

Any idea what can be wrong? I use the most recent angular 12 without custom webpack configs.

@shilman
Copy link
Member

shilman commented May 14, 2021

Can you please create a reproduction with npx sb@next repro and link me to result and I'll take a look?

@MickL
Copy link

MickL commented May 14, 2021

@shilman I have the exact same error after using npx sb upgrade --prerelease:

ERR! => Could not get angular cli webpack config
ERR! TypeError: Cannot read property 'minify' of undefined

@shilman
Copy link
Member

shilman commented May 14, 2021

Did you read the MIGRATION instructions?

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#angular-12-upgrade

@MickL
Copy link

MickL commented May 14, 2021

I did not read that. Still I get the same error :/

@eugene-stativka
Copy link

Can you please create a reproduction with npx sb@next repro and link me to result and I'll take a look?

I've tried this and it works fine. I will try to find the difference between this newly generated project and our Angular v11 upgraded to Angular v12. At first glance the difference in the console output is this:

-info => Using angular project "my-project" for configuring Storybook
-ERR! => Could not get angular cli webpack config
+info => Using angular-cli webpack config
+info => Using default Webpack5 setup

For some reason, this default Webpack5 setup is not used by Storybook.

@shilman
Copy link
Member

shilman commented May 14, 2021

@ThibaudAV does this mean anything to you? ☝️

@shilman
Copy link
Member

shilman commented May 14, 2021

@eugene-stativka are you using nx?

@eugene-stativka
Copy link

@eugene-stativka are you using nx?

no. Just official @angular/cli

@shilman
Copy link
Member

shilman commented Jun 2, 2021

@bryanrideshark can you install Webpack 5.36.2 in your project? Then angular will use it and storybook should also use it?

(Also FYI all your @storybook/* packages from the monorepo should ideally be the same version. not just the two you listed. But probably unrelated to the problem you're seeing.)

@ydmitry
Copy link

ydmitry commented Jun 2, 2021

For me works in Angular 12 with following yarn resolutions:

  "webpack": "5.38.1",
  "@my/storybook/**/css-loader": "^5.0.0",
  "@my/storybook/**/dotenv-webpack": "^6.0.0",
  "@my/storybook/**/html-webpack-plugin": "^5.0.0",
  "@my/storybook/**/style-loader": "^2.0.0",
  "@mystorybook/**/terser-webpack-plugin": "^5.1.1",
  "@my/storybook/**/webpack-dev-middleware": "^4.1.0",
  "webpack-virtual-modules": "^0.4.2"

Where @my/storybook is a yarn workspace with package.json where storybook is in dependencies

And following Storybook version: 6.2.0-beta.3

@mdeberryfadv
Copy link

I am getting the following error using Storybook 6.3.0-beta.15 and an Angular library project with Angular version 12.0.3

ERR! => Could not get angular cli webpack config
ERR! TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
ERR!     at validateString (internal/validators.js:124:11)
ERR!     at Object.resolve (path.js:154:9)
ERR!     at C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:140:47
ERR!     at step (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:69:23)
ERR!     at Object.next (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:50:53)
ERR!     at C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:44:71
ERR!     at new Promise (<anonymous>)
ERR!     at __awaiter (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:40:12)
ERR!     at buildWebpackConfigOptions (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:125:82)
ERR!     at Object.<anonymous> (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:177:42)
ERR!     at step (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:69:23)
ERR!     at Object.next (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:50:53)
ERR!     at C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:44:71
ERR!     at new Promise (<anonymous>)
ERR!     at __awaiter (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:40:12)
ERR!     at Object.extractAngularCliWebpackConfig (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:171:12)
ERR!  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
ERR!     at validateString (internal/validators.js:124:11)
ERR!     at Object.resolve (path.js:154:9)
ERR!     at C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:140:47
ERR!     at step (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:69:23)
ERR!     at Object.next (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:50:53)
ERR!     at C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:44:71
ERR!     at new Promise (<anonymous>)
ERR!     at __awaiter (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:40:12)
ERR!     at buildWebpackConfigOptions (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:125:82)
ERR!     at Object.<anonymous> (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:177:42)
ERR!     at step (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:69:23)
ERR!     at Object.next (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:50:53)
ERR!     at C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:44:71
ERR!     at new Promise (<anonymous>)
ERR!     at __awaiter (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:40:12)
ERR!     at Object.extractAngularCliWebpackConfig (C:\src\ui-components\angular-components-library\node_modules\@storybook\angular\dist\ts3.9\server\angular-devkit-build-webpack.js:171:12) {
ERR!   code: 'ERR_INVALID_ARG_TYPE'
ERR! }

@bryanrideshark
Copy link

@shilman , I had tried that and it didn't seem to work. I am using npm, not yarn, so maybe that has something to do with it?

All of my @storybook installations in package.json had the same version.

I see were are now at Storybook 6.3.0-beta.15 or higher - I will re-attempt later this week and report back if I still get problems.

@vdiaz1130
Copy link

We're on Angular 12. I tried all of the above. Initially it was the mimetype error mentioned above. Now were getting the following:

ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[18] has an unknown property 'loaders'. These properties are valid:
   object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }
   -> A rule description with conditions and effects for modules.
    at validate (yarn-proj-dir/node_modules/schema-utils/dist/validate.js:104:11)
    at validateSchema (yarn-proj-dir/node_modules/webpack/lib/validateSchema.js:78:2)
    at create (yarn-proj-dir/node_modules/webpack/lib/webpack.js:109:24)
    at webpack (yarn-proj-dir/node_modules/webpack/lib/webpack.js:151:32)
    at f (yarn-proj-dir/node_modules/webpack/lib/index.js:55:16)
    at Object.start (yarn-proj-dir/node_modules/@storybook/builder-webpack5/dist/cjs/index.js:77:18)
    at async Promise.all (index 0)
    at async storybookDevServer (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/dev-server.js:123:28)
    at async buildDevStandalone (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:110:31)
    at async Object.buildDev (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:152:5)
 ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.module.rules[18] has an unknown property 'loaders'. These properties are valid:
   object { compiler?, dependency?, descriptionData?, enforce?, exclude?, generator?, include?, issuer?, issuerLayer?, layer?, loader?, mimetype?, oneOf?, options?, parser?, realResource?, resolve?, resource?, resourceFragment?, resourceQuery?, rules?, scheme?, sideEffects?, test?, type?, use? }
   -> A rule description with conditions and effects for modules.
    at validate (yarn-proj-dir/node_modules/schema-utils/dist/validate.js:104:11)
    at validateSchema (yarn-proj-dir/node_modules/webpack/lib/validateSchema.js:78:2)
    at create (yarn-proj-dir/node_modules/webpack/lib/webpack.js:109:24)
    at webpack (yarn-proj-dir/node_modules/webpack/lib/webpack.js:151:32)
    at f (yarn-proj-dir/node_modules/webpack/lib/index.js:55:16)
    at Object.start (yarn-proj-dir/node_modules/@storybook/builder-webpack5/dist/cjs/index.js:77:18)
    at async Promise.all (index 0)
    at async storybookDevServer (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/dev-server.js:123:28)
    at async buildDevStandalone (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:110:31)
    at async Object.buildDev (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:152:5) {
  errors: [
    {
      keyword: 'oneOf',
      dataPath: '.module.rules',
      schemaPath: '#/properties/rules/oneOf',
      params: [Object],
      message: 'should match exactly one schema in oneOf',
      schema: [Array],
      parentSchema: [Object],
      data: [Array],
      children: [Array]
    }
  ],
  schema: {
    definitions: {
      Amd: [Object],
      AssetFilterItemTypes: [Object],
      AssetFilterTypes: [Object],
      AssetGeneratorDataUrl: [Object],
      AssetGeneratorDataUrlFunction: [Object],
      AssetGeneratorDataUrlOptions: [Object],
      AssetGeneratorOptions: [Object],
      AssetInlineGeneratorOptions: [Object],
      AssetModuleFilename: [Object],
      AssetParserDataUrlFunction: [Object],
      AssetParserDataUrlOptions: [Object],
      AssetParserOptions: [Object],
      AssetResourceGeneratorOptions: [Object],
      AuxiliaryComment: [Object],
      Bail: [Object],
      CacheOptions: [Object],
      CacheOptionsNormalized: [Object],
      Charset: [Object],
      ChunkFilename: [Object],
      ChunkFormat: [Object],
      ChunkLoadTimeout: [Object],
      ChunkLoading: [Object],
      ChunkLoadingGlobal: [Object],
      ChunkLoadingType: [Object],
      Clean: [Object],
      CleanOptions: [Object],
      CompareBeforeEmit: [Object],
      Context: [Object],
      CrossOriginLoading: [Object],
      Dependencies: [Object],
      DevServer: [Object],
      DevTool: [Object],
      DevtoolFallbackModuleFilenameTemplate: [Object],
      DevtoolModuleFilenameTemplate: [Object],
      DevtoolNamespace: [Object],
      EmptyGeneratorOptions: [Object],
      EmptyParserOptions: [Object],
      EnabledChunkLoadingTypes: [Object],
      EnabledLibraryTypes: [Object],
      EnabledWasmLoadingTypes: [Object],
      Entry: [Object],
      EntryDescription: [Object],
      EntryDescriptionNormalized: [Object],
      EntryDynamic: [Object],
      EntryDynamicNormalized: [Object],
      EntryFilename: [Object],
      EntryItem: [Object],
      EntryNormalized: [Object],
      EntryObject: [Object],
      EntryRuntime: [Object],
      EntryStatic: [Object],
      EntryStaticNormalized: [Object],
      EntryUnnamed: [Object],
      Environment: [Object],
      Experiments: [Object],
      ExternalItem: [Object],
      ExternalItemFunctionData: [Object],
      ExternalItemValue: [Object],
      Externals: [Object],
      ExternalsPresets: [Object],
      ExternalsType: [Object],
      FileCacheOptions: [Object],
      Filename: [Object],
      FilenameTemplate: [Object],
      FilterItemTypes: [Object],
      FilterTypes: [Object],
      GeneratorOptionsByModuleType: [Object],
      GlobalObject: [Object],
      HashDigest: [Object],
      HashDigestLength: [Object],
      HashFunction: [Object],
      HashSalt: [Object],
      HotUpdateChunkFilename: [Object],
      HotUpdateGlobal: [Object],
      HotUpdateMainFilename: [Object],
      IgnoreWarnings: [Object],
      IgnoreWarningsNormalized: [Object],
      Iife: [Object],
      ImportFunctionName: [Object],
      ImportMetaName: [Object],
      InfrastructureLogging: [Object],
      JavascriptParserOptions: [Object],
      Layer: [Object],
      Library: [Object],
      LibraryCustomUmdCommentObject: [Object],
      LibraryCustomUmdObject: [Object],
      LibraryExport: [Object],
      LibraryName: [Object],
      LibraryOptions: [Object],
      LibraryType: [Object],
      Loader: [Object],
      MemoryCacheOptions: [Object],
      Mode: [Object],
      ModuleFilterItemTypes: [Object],
      ModuleFilterTypes: [Object],
      ModuleOptions: [Object],
      ModuleOptionsNormalized: [Object],
      Name: [Object],
      NoParse: [Object],
      Node: [Object],
      NodeOptions: [Object],
      Optimization: [Object],
      OptimizationRuntimeChunk: [Object],
      OptimizationRuntimeChunkNormalized: [Object],
      OptimizationSplitChunksCacheGroup: [Object],
      OptimizationSplitChunksGetCacheGroups: [Object],
      OptimizationSplitChunksOptions: [Object],
      OptimizationSplitChunksSizes: [Object],
      Output: [Object],
      OutputModule: [Object],
      OutputNormalized: [Object],
      Parallelism: [Object],
      ParserOptionsByModuleType: [Object],
      Path: [Object],
      Pathinfo: [Object],
      Performance: [Object],
      PerformanceOptions: [Object],
      Plugins: [Object],
      Profile: [Object],
      PublicPath: [Object],
      RawPublicPath: [Object],
      RecordsInputPath: [Object],
      RecordsOutputPath: [Object],
      RecordsPath: [Object],
      Resolve: [Object],
      ResolveAlias: [Object],
      ResolveLoader: [Object],
      ResolveOptions: [Object],
      ResolvePluginInstance: [Object],
      RuleSetCondition: [Object],
      RuleSetConditionAbsolute: [Object],
      RuleSetConditionOrConditions: [Object],
      RuleSetConditionOrConditionsAbsolute: [Object],
      RuleSetConditions: [Object],
      RuleSetConditionsAbsolute: [Object],
      RuleSetLoader: [Object],
      RuleSetLoaderOptions: [Object],
      RuleSetLogicalConditions: [Object],
      RuleSetLogicalConditionsAbsolute: [Object],
      RuleSetRule: [Object],
      RuleSetRules: [Object],
      RuleSetUse: [Object],
      RuleSetUseItem: [Object],
      ScriptType: [Object],
      SnapshotOptions: [Object],
      SourceMapFilename: [Object],
      SourcePrefix: [Object],
      StatsOptions: [Object],
      StatsValue: [Object],
      StrictModuleErrorHandling: [Object],
      StrictModuleExceptionHandling: [Object],
      Target: [Object],
      TrustedTypes: [Object],
      UmdNamedDefine: [Object],
      UniqueName: [Object],
      WarningFilterItemTypes: [Object],
      WarningFilterTypes: [Object],
      WasmLoading: [Object],
      WasmLoadingType: [Object],
      Watch: [Object],
      WatchOptions: [Object],
      WebassemblyModuleFilename: [Object],
      WebpackOptionsNormalized: [Object],
      WebpackPluginFunction: [Object],
      WebpackPluginInstance: [Object]
    },
    title: 'WebpackOptions',
    description: 'Options object as provided by the user.',
    type: 'object',
    additionalProperties: false,
    properties: {
      amd: [Object],
      bail: [Object],
      cache: [Object],
      context: [Object],
      dependencies: [Object],
      devServer: [Object],
      devtool: [Object],
      entry: [Object],
      experiments: [Object],
      externals: [Object],
      externalsPresets: [Object],
      externalsType: [Object],
      ignoreWarnings: [Object],
      infrastructureLogging: [Object],
      loader: [Object],
      mode: [Object],
      module: [Object],
      name: [Object],
      node: [Object],
      optimization: [Object],
      output: [Object],
      parallelism: [Object],
      performance: [Object],
      plugins: [Object],
      profile: [Object],
      recordsInputPath: [Object],
      recordsOutputPath: [Object],
      recordsPath: [Object],
      resolve: [Object],
      resolveLoader: [Object],
      snapshot: [Object],
      stats: [Object],
      target: [Object],
      watch: [Object],
      watchOptions: [Object]
    }
  },
  headerName: 'Webpack',
  baseDataPath: 'configuration',
  postFormatter: [Function: postFormatter]
}

Removing

 core: {
    builder: 'webpack5',
  },

Produces the mimetype error

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules[9] has an unknown property 'mimetype'. These properties are valid:
   object { compiler?, enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, realResource?, resolve?, resource?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }
   -> A rule
    at webpack (yarn-proj-dir/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/webpack.js:31:9)
    at Object.start (yarn-proj-dir/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:96:18)
    at async Promise.all (index 0)
    at async storybookDevServer (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/dev-server.js:123:28)
    at async buildDevStandalone (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:110:31)
    at async Object.buildDev (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:152:5)
 WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules[9] has an unknown property 'mimetype'. These properties are valid:
   object { compiler?, enforce?, exclude?, include?, issuer?, loader?, loaders?, oneOf?, options?, parser?, query?, realResource?, resolve?, resource?, resourceQuery?, rules?, sideEffects?, test?, type?, use? }
   -> A rule
    at webpack (yarn-proj-dir/node_modules/@storybook/builder-webpack4/node_modules/webpack/lib/webpack.js:31:9)
    at Object.start (yarn-proj-dir/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:96:18)
    at async Promise.all (index 0)
    at async storybookDevServer (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/dev-server.js:123:28)
    at async buildDevStandalone (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:110:31)
    at async Object.buildDev (yarn-proj-dir/node_modules/@storybook/core-server/dist/cjs/build-dev.js:152:5)

I tried the latest and beta versions of SB libs

@ThibaudAV
Copy link
Contributor

@mdeberryfadv It looks like storybook can't read the configuration in angular.json.
Storybook is trying to use the default project (usually) to configure webpack with the assets and styles defined in angular.json.
What is your default project application ? is there an architect build with the builder @angular-devkit/build-angular:browser ?

@vdiaz1130
Copy link

Yes. We are using Nx too btw.

"build": {
  "builder": "@angular-devkit/build-angular:browser",
  ...
}...

"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  ...
}...

@mdeberryfadv
Copy link

@ThibaudAV

My default project was a library with a builder of @angular-devkit/build-angular:ng-packagr. I didn't have an application in the project, but adding one and making it the default seems to have resolved the issue.

Has storybook always required an application?

@vdiaz1130
Copy link

vdiaz1130 commented Jun 7, 2021

Along with adding the following to main.js:

core: {
    builder: 'webpack5'
  },

This fixed my issue:
image

@ThibaudAV
Copy link
Contributor

@mdeberryfadv

Has storybook always required an application?

I think it can work without it. but storybook is not tested nor designed for projects with only one library. For the moment

@activenode
Copy link
Contributor

@ThibaudAV but wouldn't a Design System (we use it like that as well) be a perfect example for using SB without an app but only a library?

@activenode
Copy link
Contributor

activenode commented Jun 8, 2021

If you point me in the right direction I am willing to fix the library problem. Until now (before 6.3) library approach has worked fine.

@ThibaudAV
Copy link
Contributor

@activenode you say that since 2.3 it does not work anymore?
I think it still works as before. but maybe I'm wrong.

I plan to work on it and to do the necessary tests so that this use case is really integrated.

If you point me in the right direction I am willing to fix the library problem. Until now (before 6.3) library approach has worked fine.

we can talk about it on discord ;)

@activenode
Copy link
Contributor

@ThibaudAV there seems to be some flakyness involved in the process.

I followed the steps above and used @next resulting in the versions 6.3.0-beta.17 related to the packages.

Then, after serving storybook (not "build"ing it but only serving it) it would stop at 99% and show an empty page not being able to fetch the assets (js, css).

So I also followed what @vdiaz1130 said and at that point it seemed to work again.

Then after deleting the app again and trying another time it also worked. Pretty much flaky.

So what seems to work "out of the box" is to simply remove node_modules and do fresh npm ci and then start it.

Could it be related to node_modules/.cache maybe?

@dom-kelly
Copy link

@ThibaudAV

My default project was a library with a builder of @angular-devkit/build-angular:ng-packagr. I didn't have an application in the project, but adding one and making it the default seems to have resolved the issue.

Has storybook always required an application?

Exactly the same for me. It would be great if we didn't need a default (dummy) application to make this work.

@ThibaudAV
Copy link
Contributor

@dominicjameskelly

I recently tested it and it seems to work on a configuration like :

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "pattern-lib": {
      "projectType": "library",
      ...
      },
      "root": "projects/pattern-lib",
      "sourceRoot": "projects/pattern-lib/src",
      "prefix": "pl",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:ng-packagr",
          "options": {
            "tsConfig": "projects/pattern-lib/tsconfig.lib.json",
            "project": "projects/pattern-lib/ng-package.json"
          },
          "configurations": {...}
        },
        "test": {...},
        "lint": {...}
        }
      }
    }
  },
  "defaultProject": "pattern-lib"
}

the important points are :

  • the architect.build (but becomes configurable with the new storybook ng builder)
  • tsConfig path in options

but it would be nice to have examples of simple projects where it doesn't work in order to progress on this feature with real use case :)

@mdeberryfadv
Copy link

@ThibaudAV, I don't have a project to share, but I have confirmed that the issue I was having was caused by the tsConfig property not being set in options.

@ThibaudAV
Copy link
Contributor

@mdeberryfadv Do you use one instance of storybook per library?
or one instance for all libraries ?

@mdeberryfadv
Copy link

@ThibaudAV The current setup is one per library

@ThibaudAV
Copy link
Contributor

@mdeberryfadv I recommend you to watch this https://gist.github.com/ThibaudAV/b5a9f993b01c3d3bbdf01c0fd8f3c73f it's brand new (some adjustments are in progress #15194)
but will allow to have a correct config per library
otherwise in your case each storybook instance will use the defaultProject config

if I am not mistaken

@shilman
Copy link
Member

shilman commented Jun 10, 2021

Hi All, It seems like Angular12 is working successfully for a lot of people, so I'm going to close this issue. If you're experiencing any problems with Angular12 compatibility, please:

  1. Search the Storybook github issues to see if there's a match, and upvote it if there is
  2. File a new issue if you can't find an existing issue

Thanks and happy hacking! 🚀

@benbrowning
Copy link

Anyone having issues after upgrading an existing project to Angular 12 - you may have missed the storybook migration guide:
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#angular-12-upgrade
Following these steps worked for me.

@SonurK
Copy link

SonurK commented Oct 20, 2021

Along with adding the following to main.js:

core: {
    builder: 'webpack5'
  },

This fixed my issue: image

This also fix my issue, I would like to add more information about it
you need to run
npm i @storybook/builder-webpack5
and
npm i @storybook/manager-webpack5
and then, in this file
.storybook/main.js
add

module.exports = {
  core: {
    builder: 'webpack5',
  },
};

Source: https://www.npmjs.com/package/@storybook/builder-webpack5

@YonathanB
Copy link

I read all the docs and all of the posts here.
And my storybook stil doesn't work since upgrading to ng12...
Am I the only one?

@shilman
Copy link
Member

shilman commented Feb 17, 2022

@YonathanB what problems are you seeing?

@YonathanB
Copy link

Hi @shilman,
I have the same problem as descrived Here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests