storybook: angular 13.1 stories file missing from the TypeScript compilation
Describe the bug When using Angular 13.1, the latest storybook, and no “storybook:build” builder, I get the following error:
Error: /{redacted}/sb-ng-performance/src/stories/Button.stories.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the ‘files’ or ‘include’ property.
To Reproduce Create a new project with Angular 13.1 and the latest storybook alpha (stable does not support ng 13.1). Make sure you don’t have a “storybook:build” configuration in your angular.json file. Try building. see this reproduction
System
System:
OS: macOS 12.0.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
Node: 12.21.0 - /usr/local/bin/node
Yarn: 3.1.1 - /usr/local/bin/yarn
npm: 7.18.1 - /usr/local/bin/npm
Browsers:
Chrome: 96.0.4664.110
Safari: 15.1
npmPackages:
@storybook/addon-actions: ^6.5.0-alpha.4 => 6.5.0-alpha.4
@storybook/addon-docs: ^6.5.0-alpha.4 => 6.5.0-alpha.4
@storybook/addon-essentials: ^6.5.0-alpha.4 => 6.5.0-alpha.4
@storybook/addon-links: ^6.5.0-alpha.4 => 6.5.0-alpha.4
@storybook/angular: 6.5.0-alpha.4 => 6.5.0-alpha.4
@storybook/builder-webpack5: ^6.5.0-alpha.4 => 6.5.0-alpha.4
@storybook/manager-webpack5: ^6.5.0-alpha.4 => 6.5.0-alpha.4
Additional context
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 73 (12 by maintainers)
I don’t really understand why this issue is closed… It is still broken for us on Angular 13.1 and storybook version 6.4.12.
For this problem I think I have found. If someone else can test it and confirm 🙏 If I delete this config https://github.com/storybookjs/storybook/blob/next/app/angular/src/server/framework-preset-angular.ts#L32-L36 inside of
framework-preset-angular.js
(you can do this by modifying your note_modules) it seems to work 🤞 I think that all (or part of) this file has nothing to do in the versions of angular >12ngx-template-loader
,sass
, … should come from what we use of angular-cli. It was the old solution used at the beginning of storybook and angular <9 before ivy and angular-cli stuff@shilman @ThibaudAV
just inited new angular app
13.1.2
, storybook (6.4.12
, viasb init
). GotError: /Users/drow/projects/tests/storybook-issues/src/stories/Button.stories.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
tried
6.5.0-alpha.16
, gotError: node_modules/@storybook/api/dist/ts3.9/lib/stories.d.ts:1:8 - error TS1259: Module '"/Users/drow/projects/tests/storybook-issues/node_modules/@types/react/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
.added
allowSyntheticDefaultImports
to roottsconfig.json
, worked fine.renamed
preview.js
topreview.ts
(like in our reall apps) - gotError: /Users/drow/projects/tests/storybook-issues/.storybook/preview.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
added
./*.ts
toincludes
field of.storybook/tsconfig.json
, gotError: .storybook/preview.ts:2:21 - error TS2732: Cannot find module '../documentation.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.
.added
resolveJsonModule
to roottsconfig.json
, gotError: .storybook/preview.ts:3:17 - error TS2345: Argument of type '{ pipes: never[]; interfaces: { name: string; id: string; file: string; deprecated: boolean; deprecationMessage: string; type: string; sourceCode: string; properties: never[]; indexSignatures: never[]; methods: never[]; }[]; ... 9 more ...; coverage: { ...; }; }' is not assignable to parameter of type 'CompodocJson'.
mocked it with
setCompodocJson(docJson as any);
, worked finelooks like too much broken stuff 😕
@literalpie using @meriturva’s steps you should see the error when running
npm run storybook
:If you update angular.json following here, and working through a few issues like
staticDir
andcompodoc
I end up with:And run command
ng run projectName:storybook
, you should then have a build, but these steps do not produce any JIT errors in console. But do produce the lack of watch/rebuild as other’s reported. But the components are not displayed how I would expect either:Following on from this I wanted to create the simplist repo (here) with issue and seems once I added Angular Material is when it happened.
Hope this helps.
I did have a few more examples in repo hoping to find a simplier way to demo the issue, but these only show the issue above where they do not look how I would expect.
Changing the default includes in
.storybook/tsconfig.json
from:to
solved the above issue for me. Not sure though if this is only a workaround.
Good golly!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.10 containing PR #17131 that references this issue. Upgrade today to the
@next
NPM tag to try it out!Closing this issue. Please re-open if you think there’s still more to do.
In my environment, changing config for AngularWebpackPlugin solved “missing from the TypeScript compilation” problem. But as others say, 2 problems persist.
1.JIT compilation error for any story that uses a component that doesn’t have an inline template but an html file 2.No live reloading when making changes
.storybook/main.js
.storybook/tsconfig.json
I can confirm there are some of these issues still happening. Angular 13.1 Storybook 6.4.13
Reproduction Repo
Running the app via ng serve compiles and loads successfully.
Re: JIT compilation errors – it appears as though new lines within a template tag are causing the template to be parsed incorrectly by the Angular compiler. When the file template is compiled into the metadata for the Component, it is escaping the newlines, for example:
Given this template:
Which is then turned into:
The parser then interprets the tag as
<my-component\\n\\t
instead of stripping the whitespace which leads to the “Opening tag not terminated” JIT error.Since this is only happening for Storybook (dev and production builds compile and execute just fine), I’m leaning toward something in the Storybook setup may not be configured properly. That said, I’m also not sure if this is a problem that Angular parser itself should handle.
I think this needs to be solved. It’s not a robust solution to inline all the templates. Good work on finding the issue though!
I’m getting the same JIT errors as @danielbater since the update to Angular 13.1 and Storybook 6.5.0-alpha.4 (also 6.4.9)
This is happening for all 35 components in a library
There were no errors with Angular 12 & Storybook 6.3
It happens when building either with
start-storybook
or when using a builder inangular.json
It looks like only #17131 is included but https://github.com/storybookjs/storybook/pull/17032 is missing so that build step already fails. Would it be possible to release that fix in 6.4.x as well?
@shilman is it possible to push this fix to 6.4? According to Storybook roadmap, 6.5 is expected only in March, such a long wait… I think everyone would appreciate if we could enjoy this fix without upgrading to unstable alpha version.
Simple step to reproduce with angular 13.1:
In my case change
.storybook/tsconfig.json
as described in https://github.com/storybookjs/storybook/issues/17039#issuecomment-997384830 doesn’t solve the issue.In my project we have two issues mentioned here:
So I can confirm that the issue you mention @meriturva also happens on my project
We actually have the same issue in our app and figured out that the problem comes from loading template files via templateUrl. If we have our template inline in the .ts file then storybook renders it properly but if we extract it to a different template (html) file and use it via templateUrl then rendering breaks with the JIT compilation error.
I got this to “build” by removing
.storybook/tsconfig.json
updatingtsconfig.app.json
However, then I am faced with JIT issues such as
Errors during JIT compilation of template for DummyComponent: Opening tag "dummy-component\n" not terminated.
Which is not the case. Another isUncaught (in promise) TypeError: n is not a function
Which looks to caused by the Zeplin addonAlso I get this when downgrading to Angular 13.0.3. not just 13.1.x.
haha,
Because I begin to know well the depths of storybook with angular and its weaknesses :p. I had already spotted the inconsistency of this config file and its possible conflict of configuration, that now is a fact.
I will prepare a PR to fix this soon
Thanks @literalpie … just run:
secondly, watch files doesn’t work anymore with angular.json as described: https://github.com/storybookjs/storybook/issues/17039#issuecomment-998216969
@literalpie I agree including everything is not a good idea, but only way I could get this to work. Yes project works fine when using Angular 12. When remaining in Angular 13 and I go back to a normal setup which for me is no tsconfig in
.storybook
:The error is the same as yours.
So I tried adding includes to my
tsconfig.app.json
to see if I can get it to build as I previously commented I did but only with a wildcard include eveything.I added a fresh new
tsconfig.json
to.storybook
folder. Somthing like this:But then continue to get cannot find stories.
@KirillMetrik absolutely. If somebody can verify the fix with the alpha, I’ll patch it back to the stable release
aaaand for this :
we now need to add this option
watch:true,
here : https://github.com/storybookjs/storybook/blob/854e37482beb3db9ddff346d995a58017b57a502/app/angular/src/server/angular-cli-webpack-13.x.x.js#L32same if some people can confirm that it works for them 🙏 🙇
but if it is well that, it should be add this option only in serve mode and not in build mode, I think
@ankor-at-ccmath just see here https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#64-angular-changes (on our projects we don’t use any inline template, just external HTML files).
Can we please have some more info on that so that we can solve the JIT issue as well?
This solution worked for mw
it does not by default but you can add an extra entry for storybook in your angular.json that specifies the
tsconfig
file you want it to use as such :I hope it helps!
@fasidOnGit Hi Fasid, thanks for thinking along! I found the cause and it is… quite random. Please check this comment: https://github.com/storybookjs/storybook/issues/14627#issuecomment-821291541 .
Turns out the spread operator used to insert the agrs was the cause of all the issues. I had to rewrite code like this:
It is a very random solution and I’m quite surprised the spread operator can’t be used this way.
I know 😃. And that’s the one I included the directory in. Not the root tsconfig.
@shilman I have just updated to version
6.5.0-alpha.10
but I’m still getting “is missing from the TypeScript compilation” errors. I’ve already tried to clean node_modules folder and reinstall packages, but nothing changes.@ThibaudAV
can confirm it does work for me 👌
@ThibaudAV holly sh**. I can CONFIRM that it works flawlessly.
Two days trying to figure out the root cause. How did you find out?
So, for the time being I used @ThibaudAV 's solution by updating
./storybook/main.js
, instead of updating.../server/framework-preset-angular.js
.See webpackFinal property:
It is quite simple:
main.js
:On our side, we have moved all storybook compilations settings to a separate project on our
angular.json
and we have no more problem with templates. The only one present is live reloading no more working.I think that the tsconfig.json file in .stories folder is not respected. It only works for me when I make the changes in the tsconfig.app.json.
Hitting the JIT error too on
6.5.0-alpha.5
. Is there any known workaround at the time?I was facing the same issue here, and what I did was comment out this lines from
tsconfig.app.json
and add**/*.stories.*
in my includes:after that I get this error:
then I solved adding
allowSyntheticDefaultImports: true
to my angularCompilerOptions, after thatnpm run storybook
worked pretty well.I hope I can help someone with this solution, and please let me know if this solution is not the best 😊