-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
False positive in ModuleScopePlugin with yarn2 "workspace:*" packages #10508
Comments
Implication here is quite serious: CRA app in yarn 2 workspace with pnp can't be split into multiple packages in the same workspace due to this check. |
This seems similar to this issue that was previously closed #8757 and not resolved. |
Also related #9226 |
For yarn this can be resolved using yarn specific lookup in the plugin to see if it is a module include https://yarnpkg.com/advanced/pnpapi/ |
I have no clue what I am doing, but using yarn patch protocol I made it work, I think diff --git a/ModuleScopePlugin.js b/ModuleScopePlugin.js
index e84d2b38aabbfc8e28515859417ae9652b711b57..8d450373ceebfd8ac747f6165f2d8822900d8b26 100644
--- a/ModuleScopePlugin.js
+++ b/ModuleScopePlugin.js
@@ -35,6 +35,12 @@ class ModuleScopePlugin {
) {
return callback();
}
+ if (process.versions.pnp) {
+ const {findPackageLocator} = require('pnpapi');
+ if (findPackageLocator(request.__innerRequest_request) !== null) {
+ return callback();
+ }
+ }
// Resolve the issuer from our appSrc and make sure it's one of our files
// Maybe an indexOf === 0 would be better?
if ( |
The workaround is not a complete check and most likely not even a part of a proper check. The idea was to see if file can be resolved to be belonging to one of the packages declared as a dependency, but that does not guarantee that it is required via dependency and not directly as a path. |
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. |
Describe the bug
ModuleScopePlugin incorrectly detects import from package in yarn 2 pnp workspace as relative path.
Same behavior is with importing .ts, so not svg specific.
Did you try recovering your dependencies?
Which terms did you search for in User Guide?
Environment
Steps to reproduce
Setup CRA in yarn 2 workspace
mkdir yarnws && cd yarnws
yarn set version berry && yarn set version latest
yarn --version
> 2.4.0yarn init -w
(cd packages/ && yarn create react-app --template typescript test-cra)
rm -rf packages/test-cra/{.pnp.js,.yarn,yarn.lock}
yarn up
yarn workspace test-cra add eslint-config-react-app react-refresh
yarn workspace test-cra start
(mkdir packages/testpkg && cd packages/testpkg && yarn init)
yarn workspace test-cra add "testpkg@workspace:*"
import { test } from 'testpkg/test'
Expected behavior
ModuleScopePlugin does not complain and does not prevent compilation
Actual behavior
Reproducible demo
https://github.com/Xerkus/cra-10508
The text was updated successfully, but these errors were encountered: