NX + Storybook: ... is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property

Viewed 916

I'm new in the world of angular, nx and storybook. I've been googling for quite a while and reading through several threads, but so far nothing has been able to help me.

I have a single Angular app with some libs. I only want one Storybook instance, which contains all the stories of the Libs. But I get the message "container.components.stories.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property"

Here are some info:

.storybook
    main.js
    tsconfig.json
apps
    myproject
        .storybook
        src
        tsconfig.json
        tsconfig.app.json
libs
    ui
        common
            src
                lib
                    container
                        container.component.ts
                        container.component.spec.ts
                        container.component.stories.ts
                        container.component.scss
                        container.component.html
  • nx report
Node : 16.13.1
OS   : win32 x64
npm  : 8.4.1

nx : 14.0.3
@nrwl/angular : 14.0.3
@nrwl/cypress : 14.0.3
@nrwl/detox : Not Found
@nrwl/devkit : 14.0.3
@nrwl/eslint-plugin-nx : 14.0.3
@nrwl/express : Not Found
@nrwl/jest : 14.0.3
@nrwl/js : Not Found
@nrwl/linter : 14.0.3
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.0.3
@nrwl/web : Not Found
@nrwl/workspace : 14.0.3
typescript : 4.6.3
rxjs : 7.4.0
---------------------------------------
Community plugins:
     @twittwer/compodoc: 1.7.0
     @compodoc/compodoc: 1.1.19
     @storybook/angular: 6.4.22
  • .storybook/main.js
module.exports = {
    stories: ['../../../libs/**/*.stories.ts'],
    addons: ['@storybook/addon-essentials'],
    // uncomment the property below if you want to apply some webpack config globally
    // webpackFinal: async (config, { configType }) => {
    //   // Make whatever fine-grained changes you need that should apply to all storybook configs

    //   // Return the altered config
    //   return config;
    // },
};
  • .storybook/tsconfig.json
{
    "extends": "../tsconfig.base.json",
    "exclude": ["../**/*.spec.js", "../**/*.test.js", "../**/*.spec.ts", "../**/*.test.ts", "../**/*.spec.tsx", "../**/*.test.tsx", "../**/*.spec.jsx", "../**/*.test.jsx"],
    "include": ["../**/*", "../../../libs/**/*"]
}
  • apps/myproject/.storybook/main.js
const rootMain = require('../../../.storybook/main');

module.exports = {
    ...rootMain,

    core: { ...rootMain.core, builder: 'webpack5' },

    stories: [...rootMain.stories, '../src/app/**/*.stories.mdx', '../src/app/**/*.stories.@(js|jsx|ts|tsx)'],
    addons: [...rootMain.addons],
    webpackFinal: async (config, { configType }) => {
        // apply any global webpack configs that might have been specified in .storybook/main.js
        if (rootMain.webpackFinal) {
            config = await rootMain.webpackFinal(config, { configType });
        }

        // add your own webpack tweaks if needed

        return config;
    },
};

I have the following questions:

  1. What do I have to do so that Storybook processes all stories from apps and libs?
  2. Why I need webpack in my package.json? When I first tried to install Storybook, no webpack module had been added. I want to avoid adding unnecessary modules.
1 Answers

Nx adds a separate level of abstraction (pain) to your code. It's feels especially strong when you use tools like Storybook and Cypress, and unfortunately, it gets worse with new versions.

  1. On the level of the library which causes the error, add "include": ["../src/**/*", "../../../**/*.stories.*"], to .storybook/tsconfig.json -- it should do the job.
  2. Unfortunately, it came with Nx/Angular 13 (though actually Storybook is the culprit I guess) -- I was unpleasantly surprised as well. Looks like webpack needs to be explicitly set as a dev dependency now. It wasn't like that before.
Related