generator-react-sdk icon indicating copy to clipboard operation
generator-react-sdk copied to clipboard

fix: `ERR_PACKAGE_PATH_NOT_EXPORTED` when react 18 is installed in project

Open Julusian opened this issue 1 year ago • 4 comments
trafficstars

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)

Julusian avatar Jun 27 '24 14:06 Julusian

/ptal

derberg avatar Aug 11 '24 18:08 derberg

@jonaslagoni @magicmatatjahu Please take a look at this PR. Thanks! :wave:

asyncapi-bot avatar Aug 11 '24 18:08 asyncapi-bot

/rtm

jonaslagoni avatar Aug 13 '24 05:08 jonaslagoni

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.

Julusian avatar Sep 11 '24 12:09 Julusian

@all-contributors please add @Julusian for bugs, test, code

jonaslagoni avatar Sep 11 '24 13:09 jonaslagoni

@jonaslagoni

I've put up a pull request to add @Julusian! :tada:

allcontributors[bot] avatar Sep 11 '24 13:09 allcontributors[bot]

:tada: This PR is included in version 1.1.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

asyncapi-bot avatar Sep 11 '24 13:09 asyncapi-bot