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 "portal:" local components import compilation failure because of ModuleScopePlugin #9226

Open
jonenst opened this issue Jun 26, 2020 · 7 comments

Comments

@jonenst
Copy link

jonenst commented Jun 26, 2020

Describe the bug

Description here: https://stackoverflow.com/questions/61530712/module-not-found-error-using-yarn-2-to-link-react-components

TLDR:
When adding "MyExternalComponent": "portal:../MyExternalComponent" dependencies to package.json, and importing the component with import Mycomponent from MyExternalComponent, the build fails because of the ModuleScopePlugin restriction "You attempted to import components which falls outside of the project src/ directory"

Which terms did you search for in User Guide?

"yarn 2 ModuleScopePlugin"
"portal: ModuleScopePlugin"

Environment

yarn2

(paste the output of the command here.)

Steps to reproduce

(Write your steps here:)

  1. create a package in folder Foo
  2. yarn dlx create-react-app Bar
  3. add "Foo": "portal:../Foo" to Bar's package.json
    4 build Bar

Expected behavior

Should work

Actual behavior

compilation error: "You attempted to import components which falls outside of the project src/ directory"

Reproducible demo

https://bitbucket.org/cjmyles/yarn2-link/commits/e02b93771dfded0215bdba456d31aea011367807

@stale
Copy link

stale bot commented Jul 26, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jul 26, 2020
@jonenst
Copy link
Author

jonenst commented Jul 26, 2020

Still unsolved

@stale stale bot removed the stale label Jul 26, 2020
@skoging
Copy link
Contributor

skoging commented Aug 14, 2020

Same issue in workspaces with Yarn 2

@stale
Copy link

stale bot commented Sep 13, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Sep 13, 2020
@jonenst
Copy link
Author

jonenst commented Sep 13, 2020 via email

@stale stale bot removed the stale label Sep 13, 2020
@itaylor
Copy link

itaylor commented Oct 26, 2020

I had the same problem, ended up having to eject and remove ModuleScopePlugin

I understand that it CRA wants to prevent me from doing import foo from '../../../../bar' but the way ModuleScopePlugin is implemented means you can't use the linking features of yarn, lerna, etc. My imports look like this import foo from 'bar' and are linked using my package manager, which should be fine IMO.

@idubrov
Copy link

idubrov commented Dec 15, 2020

For what it's worth, if you are using yarn v2, you can use their patch protocol to patch react-scripts to not include the ModuleScopePlugin (so you don't have to eject).

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

No branches or pull requests

5 participants