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

TypeError: Cannot read property 'use' of undefined #16

Open
MrJadaml opened this issue Aug 15, 2021 · 7 comments
Open

TypeError: Cannot read property 'use' of undefined #16

MrJadaml opened this issue Aug 15, 2021 · 7 comments
Assignees

Comments

@MrJadaml
Copy link

MrJadaml commented Aug 15, 2021

Running into the following error after installing this preset. This is a fresh install of storybook (on CRA) with only sass preset added so far.

$ start-storybook -p 6006 -s public
info @storybook/react v6.3.7
info
info => Loading presets
info => Serving static files from ./public at /
info => Loading 1 config file in "/Users/foo/projects/pattern-library/.storybook"
info => Loading 9 other files in "/Users/foo/projects/pattern-library/.storybook"
info => Adding stories defined in "/Users/foo/projects/pattern-library/.storybook/main.js"
info => Loading Webpack configuration from `node_modules/react-scripts`
info => Removing existing JavaScript and TypeScript rules.
info => Modifying Create React App rules.
ERR! TypeError: Cannot read property 'use' of undefined
ERR!     at Object.webpackFinal (/Users/foo/projects/pattern-library/node_modules/storybook-css-modules-preset/index.js:21:24)
ERR!     at /Users/foo/projects/pattern-library/node_modules/@storybook/core-common/dist/cjs/presets.js:274:28
ERR!     at async Object.webpack (/Users/foo/projects/pattern-library/node_modules/@storybook/builder-webpack4/dist/cjs/presets/custom-webpack-preset.js:36:28)
ERR!     at async Object.start (/Users/foo/projects/pattern-library/node_modules/@storybook/builder-webpack4/dist/cjs/index.js:95:16)
ERR!     at async Promise.all (index 0)
ERR!     at async storybookDevServer (/Users/foo/projects/pattern-library/node_modules/@storybook/core-server/dist/cjs/dev-server.js:123:28)
ERR!     at async buildDevStandalone (/Users/foo/projects/pattern-library/node_modules/@storybook/core-server/dist/cjs/build-dev.js:112:31)
ERR!     at async buildDev (/Users/foo/projects/pattern-library/node_modules/@storybook/core-server/dist/cjs/build-dev.js:154:5)

my config:

module.exports = {
  ...
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/preset-create-react-app',
    'storybook-css-modules-preset',
  ],
}

my other dependencies/loaders

  "devDependencies": {
    "@storybook/addon-actions": "^6.3.7",
    "@storybook/addon-essentials": "^6.3.7",
    "@storybook/addon-links": "^6.3.7",
    "@storybook/node-logger": "^6.3.7",
    "@storybook/preset-create-react-app": "^3.2.0",
    "@storybook/preset-scss": "^1.0.3",
    "@storybook/react": "^6.3.7",
    "css-loader": "5.2.6",
    "sass": "^1.37.5",
    "sass-loader": "10.1.1",
    "storybook-css-modules-preset": "^1.1.1",
    "style-loader": "2.0.0"
  }

If I jump into the package and log out config.module.rules I get the following:

[
  { test: /\.md$/, use: [ [Object] ] },
  { test: /(stories|story)\.mdx$/, use: [ [Object], [Object] ] },
  {
    test: /\.mdx$/,
    exclude: /(stories|story)\.mdx$/,
    use: [ [Object], [Object] ]
  },
  {
    test: /\.(stories|story)\.[tj]sx?$/,
    loader: '/Users/foo/projects/pattern-library/node_modules/@storybook/source-loader/dist/cjs/index.js',
    options: { injectStoryParameters: true, inspectLocalDependencies: true },
    enforce: 'pre'
  },
  { parser: { requireEnsure: false } },
  {
    oneOf: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ]
  }
]
@JohannesKlauss
Copy link

Getting the same error

@DaveMBush
Copy link

For what its worth, I'm using NRWL/NX. It turns out, with the latest bits this plugin is no longer necessary to get css modules working with React. Putting this here just in case this happens to be the issue others are having.

The reason use is being called on undefined is because the search for the existing css loaders returns nothing. I was seeing the issue because the addon I was using from nrwl, apparently, removes the items. 🤷‍♂️

Hope this helps someone

@Negan1911
Copy link
Owner

Weird, so NX is the culprit of it? @JohannesKlauss are you using NX too?

@Negan1911 Negan1911 self-assigned this Aug 27, 2021
@JohannesKlauss
Copy link

JohannesKlauss commented Aug 27, 2021

No, it's unrelated to nx. I get that error on nx projects too, but also on non nx projects.

@Negan1911
Copy link
Owner

Negan1911 commented Aug 27, 2021

@JohannesKlauss Can you please create a simple reproduction repo?

@JohannesKlauss
Copy link

JohannesKlauss commented Sep 9, 2021

You just create a CRA app, add Storybook, add the plugin and Storybook doesn't work anymore.

Repository owner deleted a comment from lkashef Dec 6, 2021
@stovv
Copy link

stovv commented Mar 2, 2022

This preset filters oneOf from config.module.rules Sections, because the condition
_ && _.test && _.test.toString() ! == css_regex Needless.
I think it is necessary to correct the condition for something like that
_ && (_.test && _.test.toString() ! == css_regex) || _.test === undefined)

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

No branches or pull requests

5 participants