Trying to require the package "@emotion/core" without it being listed in its dependencies
See original GitHub issueDescribe the bug
When using sotrybook within a yarn PnP project, we get this error:
Trying to require the package "@emotion/core" without it being listed in its dependencies
Here is how to fix this:
Fixes for https://github.com/storybooks/storybook/issues/5919 do not fix this.
To Reproduce
- Take a valid storybook project
- Enable yarn pnp on the project by adding this to
package.json
:
"installConfig": {
"pnp": true
},
storybook start
Expected behavior
Correct dependency declaration that does not create this problem
Screenshots
ERR! Error: Package "@storybook/ui@5.0.11" (via "/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js") is trying to require the package "@emotion/core" (via "@emotion/core/package.json") without it being listed in its dependencies (@storybook/addons, @storybook/client-logger, @storybook/components, @storybook/core-events, @storybook/router, @storybook/theming, core-js, fast-deep-equal, fuzzy-search, global, history, keycode, lodash.debounce, lodash.isequal, lodash.mergewith, lodash.pick, lodash.sortby, lodash.throttle, markdown-to-jsx, memoizerific, polished, prop-types, qs, react, react-dom, react-draggable, react-helmet-async, react-hotkeys, react-lifecycles-compat, react-modal, react-resize-detector, recompose, semver, telejson, util-deprecate, @storybook/ui)
ERR! at makeError (/Users/vincent/Code/sterblue/.pnp.js:55:17)
ERR! at Object.resolveToUnqualified (/Users/vincent/Code/sterblue/.pnp.js:34411:17)
ERR! at Object.resolveRequest (/Users/vincent/Code/sterblue/.pnp.js:34482:31)
ERR! at Function.Module._resolveFilename (/Users/vincent/Code/sterblue/.pnp.js:34664:30)
ERR! at Function.resolve (internal/modules/cjs/helpers.js:30:19)
ERR! at Object.<anonymous> (/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js:6:36)
ERR! at Module._compile (internal/modules/cjs/loader.js:701:30)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
ERR! at Module.load (internal/modules/cjs/loader.js:600:32)
ERR! at Function.Module._load (/Users/vincent/Code/sterblue/.pnp.js:34607:14)
ERR! at Module.require (internal/modules/cjs/loader.js:637:17)
ERR! at require (internal/modules/cjs/helpers.js:22:18)
ERR! at Object.<anonymous> (/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-core-5.0.11-e941cf18ef62ee962607d1fb24c57b9cafc88cfd/node_modules/@storybook/core/dist/server/manager/manager-webpack.config.js:18:37)
ERR! at Module._compile (internal/modules/cjs/loader.js:701:30)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
ERR! at Module.load (internal/modules/cjs/loader.js:600:32)
ERR! { Error: Package "@storybook/ui@5.0.11" (via "/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js") is trying to require the package "@emotion/core" (via "@emotion/core/package.json") without it being listed in its dependencies (@storybook/addons, @storybook/client-logger, @storybook/components, @storybook/core-events, @storybook/router, @storybook/theming, core-js, fast-deep-equal, fuzzy-search, global, history, keycode, lodash.debounce, lodash.isequal, lodash.mergewith, lodash.pick, lodash.sortby, lodash.throttle, markdown-to-jsx, memoizerific, polished, prop-types, qs, react, react-dom, react-draggable, react-helmet-async, react-hotkeys, react-lifecycles-compat, react-modal, react-resize-detector, recompose, semver, telejson, util-deprecate, @storybook/ui)
ERR! at makeError (/Users/vincent/Code/sterblue/.pnp.js:55:17)
ERR! at Object.resolveToUnqualified (/Users/vincent/Code/sterblue/.pnp.js:34411:17)
ERR! at Object.resolveRequest (/Users/vincent/Code/sterblue/.pnp.js:34482:31)
ERR! at Function.Module._resolveFilename (/Users/vincent/Code/sterblue/.pnp.js:34664:30)
ERR! at Function.resolve (internal/modules/cjs/helpers.js:30:19)
ERR! at Object.<anonymous> (/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js:6:36)
ERR! at Module._compile (internal/modules/cjs/loader.js:701:30)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
ERR! at Module.load (internal/modules/cjs/loader.js:600:32)
ERR! at Function.Module._load (/Users/vincent/Code/sterblue/.pnp.js:34607:14)
ERR! at Module.require (internal/modules/cjs/loader.js:637:17)
ERR! at require (internal/modules/cjs/helpers.js:22:18)
ERR! at Object.<anonymous> (/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-core-5.0.11-e941cf18ef62ee962607d1fb24c57b9cafc88cfd/node_modules/@storybook/core/dist/server/manager/manager-webpack.config.js:18:37)
ERR! at Module._compile (internal/modules/cjs/loader.js:701:30)
ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
ERR! at Module.load (internal/modules/cjs/loader.js:600:32)
ERR! stack:
ERR! 'Error: Package "@storybook/ui@5.0.11" (via "/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js") is trying to require the package "@emotion/core" (via "@emotion/core/package.json") without it being listed in its dependencies (@storybook/addons, @storybook/client-logger, @storybook/components, @storybook/core-events, @storybook/router, @storybook/theming, core-js, fast-deep-equal, fuzzy-search, global, history, keycode, lodash.debounce, lodash.isequal, lodash.mergewith, lodash.pick, lodash.sortby, lodash.throttle, markdown-to-jsx, memoizerific, polished, prop-types, qs, react, react-dom, react-draggable, react-helmet-async, react-hotkeys, react-lifecycles-compat, react-modal, react-resize-detector, recompose, semver, telejson, util-deprecate, @storybook/ui)\n at makeError (/Users/vincent/Code/sterblue/.pnp.js:55:17)\n at Object.resolveToUnqualified (/Users/vincent/Code/sterblue/.pnp.js:34411:17)\n at Object.resolveRequest (/Users/vincent/Code/sterblue/.pnp.js:34482:31)\n at Function.Module._resolveFilename (/Users/vincent/Code/sterblue/.pnp.js:34664:30)\n at Function.resolve (internal/modules/cjs/helpers.js:30:19)\n at Object.<anonymous> (/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js:6:36)\n at Module._compile (internal/modules/cjs/loader.js:701:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)\n at Module.load (internal/modules/cjs/loader.js:600:32)\n at Function.Module._load (/Users/vincent/Code/sterblue/.pnp.js:34607:14)\n at Module.require (internal/modules/cjs/loader.js:637:17)\n at require (internal/modules/cjs/helpers.js:22:18)\n at Object.<anonymous> (/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-core-5.0.11-e941cf18ef62ee962607d1fb24c57b9cafc88cfd/node_modules/@storybook/core/dist/server/manager/manager-webpack.config.js:18:37)\n at Module._compile (internal/modules/cjs/loader.js:701:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)\n at Module.load (internal/modules/cjs/loader.js:600:32)',
ERR! code: 'UNDECLARED_DEPENDENCY',
ERR! data:
ERR! { request: '@emotion/core/package.json',
ERR! issuer:
ERR! '/Users/vincent/Library/Caches/Yarn/v4/npm-@storybook-ui-5.0.11-207f767d96e40513bb3887b428a4d9a81d027051/node_modules/@storybook/ui/paths.js',
ERR! issuerLocator: { name: '@storybook/ui', reference: '5.0.11' },
ERR! dependencyName: '@emotion/core',
ERR! candidates:
ERR! [ '@storybook/addons',
ERR! '@storybook/client-logger',
ERR! '@storybook/components',
ERR! '@storybook/core-events',
ERR! '@storybook/router',
ERR! '@storybook/theming',
ERR! 'core-js',
ERR! 'fast-deep-equal',
ERR! 'fuzzy-search',
ERR! 'global',
ERR! 'history',
ERR! 'keycode',
ERR! 'lodash.debounce',
ERR! 'lodash.isequal',
ERR! 'lodash.mergewith',
ERR! 'lodash.pick',
ERR! 'lodash.sortby',
ERR! 'lodash.throttle',
ERR! 'markdown-to-jsx',
ERR! 'memoizerific',
ERR! 'polished',
ERR! 'prop-types',
ERR! 'qs',
ERR! 'react',
ERR! 'react-dom',
ERR! 'react-draggable',
ERR! 'react-helmet-async',
ERR! 'react-hotkeys',
ERR! 'react-lifecycles-compat',
ERR! 'react-modal',
ERR! 'react-resize-detector',
ERR! 'recompose',
ERR! 'semver',
ERR! 'telejson',
ERR! 'util-deprecate',
ERR! '@storybook/ui' ] } }
Code snippets If applicable, add code samples to help explain your problem.
System:
- OS: MacOS
- Device: Macbook Pro 2018
- Framework: react
- Version: 5.0.11
Additional context
@arcanis Should now about this
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:19 (17 by maintainers)
Top Results From Across the Web
Module not found: Can't resolve '@emotion/react'
I had a similar issue and I resolved it by calling: npm install @emotion/react. or yarn add @emotion/react.
Read more >Module not found: Can't resolve @emotion/react | bobbyhadz
The commands will add the emotion package to the dependencies of your project. Make sure to restart your development server and your IDE...
Read more >the `@emotion/core` package has been renamed to ... - You.com
Apparently in Emotion 11, @emotion/core was renamed to @emotion/react, ... has been removed and all its exports were moved to `@emotion/react` package.
Read more >Getting Started - Chakra UI
Install Chakra UI and its peer dependencies. npm install @chakra-ui/core @emotion/core @emotion/styled emotion-theming. npm install @ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I made a quick first pass. My methodology:
This gives us a project with Storybook using Yarn v2 (Yarn v2 is where most of the development occurs nowadays, and in particular it uses PnP by default; it’s the best place to debug such issues).
I had to do the following changes to the resulting lockfile in order to get somewhere (note that except for
pnp-webpack-plugin
, all those dependencies should be listed regardless of whether we’re operating in PnP or non-PnP mode; not listing them makes Storybook subject to hoisting issues):pnp-webpack-plugin
to the dependenciesbabel-plugin-add-react-displayname
to the dependencies@emotion/core
to the dependencies@emotion/styled
to the dependencies@storybook/channel
to the dependenciesemotion-theming
to the dependenciesregenerator-runtime
to the dependenciesAdditionally, I had to “unplug” Storybook in my package.json, as it tries to create new directories inside its own directory at runtime (Yarn 2 keeps by default all packages within their own archives, which prevents them from modifying their sources. Unplugging a package means that it will be unpacked within their own directory, which we don’t recommend as it breaks zero-installs):
The
pnp-webpack-plugin
now has to be injected inside the configuration. I found a few places where this needs to be done:Again, I don’t know much about Storybook so I find it curious that there are so many different configuration files - maybe I’m missing something? In particular, the
base-webpack
file doesn’t seem to be reused byiframe-webpack
andmanager-webpack
, so I don’t know what uses it. Regardless, they need to be modified to contain a code similar to this pseudocode:The
babel-loader
helper also has to be modified to userequire.resolve('babel-loader')
instead of justbabel-loader
.After following all those steps I ended up on something that builds, but running it I get a runtime error:
The faulty code is the
module.exports
assignment in the following snippet:I’m not exactly sure what causes this; more investigation will be needed once the first issues I’ve reported have been fixed!
OMG Ok This works 🎉
It was painful, but it works and the solution is relatively simple in the end, thanks to presets.
The solution is a combination of @arcanis answers + this storybook preset
I will probably make a PR on Friday.
Thanks all !