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

fix: ERR_PACKAGE_PATH_NOT_EXPORTED when react 18 is installed in project #242

Merged
merged 7 commits into from
Sep 11, 2024

Conversation

Julusian
Copy link
Contributor

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)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@derberg
Copy link
Member

derberg commented Aug 11, 2024

/ptal

@asyncapi-bot
Copy link
Contributor

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

@jonaslagoni
Copy link
Member

/rtm

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Windows does not like your paths.. I had the same problem in some of my libraries, my solution was to simplify what part of the path was tested 🙂

@Julusian
Copy link
Contributor Author

Julusian commented Sep 11, 2024

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.

Copy link

sonarcloud bot commented Sep 11, 2024

@jonaslagoni jonaslagoni merged commit 6b948cb into asyncapi:master Sep 11, 2024
9 checks passed
@jonaslagoni
Copy link
Member

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

Copy link
Contributor

@jonaslagoni

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

@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants