Skip to content

Doesn't work with yarn berry PnP mode #41

Description

@dobesv

I tried migrating to this but I get an error when it tries to resolve the path to a css file:

 @dr.pogodin/babel-plugin-react-css-modules tried to access @draft-js-plugins/alignment, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: @draft-js-plugins/alignment (via "@draft-js-plugins/alignment/lib/plugin.css")
Required by: @dr.pogodin/babel-plugin-react-css-modules@virtual:978be09f033f9d1d87a6ae470cf41768305eae1692596bdc022dee76fc3671ae951ebf07cf433ace646b0e1c79a9e1b2be00e15f7afac12075ecdcf897b30d3a#npm:6.9.4 (via /home/dobes/projects/formative/app/.yarn/__virtual__/@dr.pogodin-babel-plugin-react-css-modules-virtual-cbe7ecd98b/0/cache/@dr.pogodin-babel-plugin-react-css-modules-npm-6.9.4-458b93ef69-ad14c19a11.zip/node_modules/@dr.pogodin/babel-plugin-react-css-modules/dist/)

In Yarn PnP environments you cannot use require directly to access the dependencies of the packages that use your package. You have to do something like:

import { createRequire } from 'node:module';

// Sometime later

function resolveUsingImportLogic(path, projectDir = process.cwd()) {
  const targetRequire = createRequire(
    path.resolve(projectDir, 'package.json'),
  );
  const resolvedPath = targetRequire.resolve(thingYouWantToResolve);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    On HoldThe issue blocked by somethingP2Important. Nice to have improvements and optimizations.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions