generator-react-sdk
generator-react-sdk copied to clipboard
fix: `ERR_PACKAGE_PATH_NOT_EXPORTED` when react 18 is installed in project
Description
If react 18 is installed into the project, the generator can get confused and use 18 when transpiling.
This is a problem as the file ./cjs/react-jsx-runtime.production.min is not exported by react anymore, resulting in the generation failing:
Something went wrong:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './cjs/react-jsx-runtime.production.min' is not defined by "exports" in <snip>/node_modules/react/package.json
at new NodeError (node:internal/errors:399:5)
at exportsNotFound (node:internal/modules/esm/resolve:361:10)
at packageExportsResolve (node:internal/modules/esm/resolve:697:9)
at resolveExports (node:internal/modules/cjs/loader:567:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:636:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1063:27)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (<snip>/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
at Function.Module._load (node:internal/modules/cjs/loader:922:27)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:110:18)
This fixes the issue, by passing the bundler the absolute path to the react file to use, resulting in it always using the react 17 that is a dependency of this library
Related issue(s)
/ptal
@jonaslagoni @magicmatatjahu Please take a look at this PR. Thanks! :wave:
/rtm
I have now run the tests locally on both linux and windows, and they are passing.
I don't like the fix I did for them, but didn't know how else to solve it. Without the .replace(/\\/g, '/') in transpiler.ts, the paths ending up in the produced file were corrupt and looked like c:\\path\\to\\node_modules\eact\\cjs\\thing.js, where a slash and r got combined/lost. This mitigates that by sticking to unix style paths throughout.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
@all-contributors please add @Julusian for bugs, test, code
:tada: This PR is included in version 1.1.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket: