Commit f97880c
**What's the problem this PR addresses?**
When chaining Yarn PNP ESM loader with
[import-in-the-middle](https://github.com/DataDog/import-in-the-middle)
loader, INVALID_URL_SCHEME is thrown because `fileURLToPath()` is run on
a parent URL of `node:util?iitm=true` generated by the IITM loader.
```
2023-03-30T21:40:58.280Z 3364766 U TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
2023-03-30T21:40:58.280Z 3364766 U at new NodeError (node:internal/errors:399:5)
2023-03-30T21:40:58.280Z 3364766 U at fileURLToPath (node:internal/url:1212:11)
2023-03-30T21:40:58.280Z 3364766 U at resolve$1 (file:///home/lizf/eve-roster/.pnp.loader.mjs:1993:77)
2023-03-30T21:40:58.280Z 3364766 U at nextResolve (node:internal/modules/esm/hooks:654:28)
2023-03-30T21:40:58.280Z 3364766 U at Hooks.resolve (node:internal/modules/esm/hooks:309:30)
2023-03-30T21:40:58.280Z 3364766 U at ESMLoader.resolve (node:internal/modules/esm/loader:312:26)
2023-03-30T21:40:58.280Z 3364766 U at ESMLoader.getModuleJob (node:internal/modules/esm/loader:172:38)
2023-03-30T21:40:58.281Z 3364766 U at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
2023-03-30T21:40:58.281Z 3364766 U at link (node:internal/modules/esm/module_job:75:36) {
2023-03-30T21:40:58.281Z 3364766 U code: 'ERR_INVALID_URL_SCHEME'
2023-03-30T21:40:58.281Z 3364766 U }
2023-03-30T21:40:58.281Z 3364766 U
2023-03-30T21:40:58.281Z 3364766 U Node.js v19.8.1
```
**How did you fix it?**
Ensure fileURLToPath() is only run on file URLs by explicitly checking
the URL protocol; if it is not `file`, then default to CWD.
**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
---------
Co-authored-by: merceyz <[email protected]>
1 parent 80302c3 commit f97880c
File tree
4 files changed
+88
-4
lines changed- .yarn/versions
- packages
- acceptance-tests/pkg-tests-specs/sources
- yarnpkg-pnp/sources/esm-loader
- hooks
4 files changed
+88
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
Lines changed: 59 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
970 | 971 | | |
971 | 972 | | |
972 | 973 | | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
973 | 1030 | | |
974 | 1031 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
0 commit comments