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

yarn 2: styled-components tried to access babel-plugin-macros, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound #3082

Open
oscar-b opened this issue Mar 31, 2020 · 7 comments

Comments

@oscar-b
Copy link
Contributor

oscar-b commented Mar 31, 2020

Environment

System:

  • OS: macOS 10.15.4
  • CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  • Memory: 138.32 MB / 16.00 GB
  • Shell: 3.0.2 - /usr/local/bin/fish

Binaries:

  • Node: 10.15.3 - /usr/local/bin/node
  • Yarn: 2.0.0-rc.31 - /usr/local/bin/yarn
  • npm: 6.4.1 - /usr/local/bin/npm

Reproduction

Set up Create React App and activate yarn 2:

yarn policies set-version berry # below v1.22
yarn set version berry          # on v1.22+

Steps to reproduce

Import styled-components/macro. On run, yarn pnp mode gives an error:

Error: /Users/oscar/dev/project/web/src/App.tsx: styled-components tried to access babel-plugin-macros, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: babel-plugin-macros (via "babel-plugin-macros")
Required by: styled-components@virtual:0d5aa5500cbca2d3fcc21adcb64334074e8710671acd4ae29d1af3c365b4c3dba1ae60e06b992407726ee5d7ee53328c19666ae24231cca5934da6e9af9e4e8a#npm:5.0.1 (via /Users/oscar/dev/project/.yarn/$$virtual/styled-components-virtual-2f170adae1/0/cache/styled-components-npm-5.0.1-87fcb612e6-2.zip/node_modules/styled-components/dist/)

Require stack:
- /Users/oscar/dev/project/.yarn/$$virtual/styled-components-virtual-2f170adae1/0/cache/styled-components-npm-5.0.1-87fcb612e6-2.zip/node_modules/styled-components/dist/styled-components-macro.cjs.js
- /Users/oscar/dev/project/.yarn/cache/babel-plugin-macros-npm-2.8.0-451367d7e7-2.zip/node_modules/babel-plugin-macros/dist/index.js
- /Users/oscar/dev/project/.yarn/cache/babel-preset-react-app-npm-9.1.2-dce39fa2e0-2.zip/node_modules/babel-preset-react-app/create.js
- /Users/oscar/dev/project/.yarn/cache/babel-preset-react-app-npm-9.1.2-dce39fa2e0-2.zip/node_modules/babel-preset-react-app/index.js
- /Users/oscar/dev/project/.yarn/cache/@babel-core-npm-7.9.0-f059c18399-2.zip/node_modules/@babel/core/lib/config/files/plugins.js
- /Users/oscar/dev/project/.yarn/cache/@babel-core-npm-7.9.0-f059c18399-2.zip/node_modules/@babel/core/lib/config/files/index.js
- /Users/oscar/dev/project/.yarn/cache/@babel-core-npm-7.9.0-f059c18399-2.zip/node_modules/@babel/core/lib/index.js
- /Users/oscar/dev/project/.yarn/$$virtual/babel-loader-virtual-c1e9567555/0/cache/babel-loader-npm-8.1.0-e8c38740ba-2.zip/node_modules/babel-loader/lib/index.js
- /Users/oscar/dev/project/.yarn/cache/loader-runner-npm-2.4.0-c414104c2f-2.zip/node_modules/loader-runner/lib/loadLoader.js
- /Users/oscar/dev/project/.yarn/cache/loader-runner-npm-2.4.0-c414104c2f-2.zip/node_modules/loader-runner/lib/LoaderRunner.js
- /Users/oscar/dev/project/.yarn/cache/webpack-npm-4.42.0-16931ca611-2.zip/node_modules/webpack/lib/NormalModule.js
- /Users/oscar/dev/project/.yarn/cache/webpack-npm-4.42.0-16931ca611-2.zip/node_modules/webpack/lib/NormalModuleFactory.js
- /Users/oscar/dev/project/.yarn/cache/webpack-npm-4.42.0-16931ca611-2.zip/node_modules/webpack/lib/Compiler.js
- /Users/oscar/dev/project/.yarn/cache/webpack-npm-4.42.0-16931ca611-2.zip/node_modules/webpack/lib/webpack.js
- /Users/oscar/dev/project/.yarn/$$virtual/react-scripts-virtual-42170a1c8f/0/cache/react-scripts-npm-3.4.1-6d60154e83-2.zip/node_modules/react-scripts/scripts/start.js

@oscar-b
Copy link
Contributor Author

oscar-b commented Mar 31, 2020

This seems to work as a temporary workaround, in .yarnrc.yml:

packageExtensions:
  "styled-components@*":
    dependencies:
      "babel-plugin-macros": "*"

@oscar-b
Copy link
Contributor Author

oscar-b commented Mar 31, 2020

Here is a repo reproducing the issue with CRA: https://github.com/oscar-b/styled-pnp

@oscar-b oscar-b changed the title styled-components tried to access babel-plugin-macros, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound yarn 2: styled-components tried to access babel-plugin-macros, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound Mar 31, 2020
oscar-b added a commit to oscar-b/styled-pnp that referenced this issue Apr 1, 2020
@rek
Copy link

rek commented Sep 24, 2020

Note: make sure to run yarn again after changing the .yarnrc.yml to include the missing deps:

packageExtensions:
  styled-components@*:
    dependencies:
      babel-plugin-macros: '*'
      react-is: '*'

@cozimacode
Copy link

cozimacode commented Oct 8, 2020

Note: make sure to run yarn again after changing the .yarnrc.yml to include the missing deps:

packageExtensions:
  styled-components@*:
    dependencies:
      babel-plugin-macros: '*'
      react-is: '*'

I owe you big time, @rek

I was on the verge of pulling my hair trying to figure out why packageExtensions was not working. Not even a single resource in the numerous ones I checked mentioned the point that you did. Thanks a lot!

@kachkaev
Copy link
Member

kachkaev commented Oct 18, 2020

I’m not relying on babel-plugin-macros, but have faced the same issue for react-is. The solution was adding this to the project’s .yarnrc.yml:

packageExtensions:
  styled-components@*:
    dependencies:
      react-is: "*"

I guess that if we add react-is and babel-plugin-macros as package dependencies, this issue will be resolved. Any thoughts why we should not be doing this?

@tabullarasa

This comment has been minimized.

reesekimm added a commit to reesekimm/timespark-fe that referenced this issue Jan 30, 2023
(node:58583) [MODULE_NOT_FOUND] Error: vite tried to access supports-color, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:58583) [MODULE_NOT_FOUND] Error: debug tried to access supports-color (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

references
- styled-components/styled-components#3082 (comment)
- https://yarnpkg.com/configuration/yarnrc#packageExtensions
reesekimm added a commit to reesekimm/timespark-fe that referenced this issue Jan 30, 2023
(node:58583) [MODULE_NOT_FOUND] Error: vite tried to access supports-color, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:58583) [MODULE_NOT_FOUND] Error: debug tried to access supports-color (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

references
- styled-components/styled-components#3082 (comment)
- https://yarnpkg.com/configuration/yarnrc#packageExtensions
@quantizor
Copy link
Contributor

There is a vote in progress to potentially remove the babel macro due to lack of usage/interest, please vote if you care thanks. #4064 (comment)

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

6 participants