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

missing dependency makes import fail with yarn 2 #362

Closed
bradennapier opened this issue Mar 25, 2022 · 10 comments
Closed

missing dependency makes import fail with yarn 2 #362

bradennapier opened this issue Mar 25, 2022 · 10 comments

Comments

@bradennapier
Copy link

It is important with yarn v2+ that all your dependencies you use are included in your package.json

By default right now this fails due to a requirement for module rehype-prism-plus. That is not in your dependencies. I am guessing it is depended on by another dependency, which is no longer allowed with yarn v2.

It would be ideal if y'all could simply add that as a dependency.

Once I did this, everything worked fine with my setup. Thanks!

For those running into this, had to edit .yarnrc.yml and have:

packageExtensions:
  "@uiw/react-md-editor@*":
    dependencies:
      "rehype-prism-plus": "*"
@bradennapier bradennapier changed the title missing dependency missing dependency makes import fail with yarn 2 Mar 25, 2022
@jaywcjlove
Copy link
Member

I'm not using yarn 2 and I'm not sure why the problem occurs.

@uiw/react-md-editor@3.11.2 
└─┬ @uiw/react-markdown-preview@4.0.5
  └── rehype-prism-plus@1.3.2

It doesn't seem to lack rehype-prism-plus dependencies.

@bradennapier

@bradennapier
Copy link
Author

react-md-editor imports it directly, making it a dependency of this package as well as of the markdown preview so it should be in the dependencies.

@jaywcjlove
Copy link
Member

My understanding is not so. Whether to depend on rehype-prism-plus depends on @uiw/react-markdown-preview.
@bradennapier

Previously, we also replaced @mapbox/rehype-prism with the dependency rehype-prism-plus。

@bradennapier
Copy link
Author

bradennapier commented Mar 25, 2022

https://github.com/uiwjs/react-md-editor/blob/master/src/components/TextArea/Markdown.tsx#L3

react-md-editor directly depends on the package here, making it a direct dependency of react-md-editor as well. While previously yarn and npm still allow it as long as one of the dependencies of yours has it as their dependency, but it is still invalid and with yarn 2 they made it an error (which has to be resolved by adding a package extension that fixes your package json).

No one can use this package if they use yarn 2.

Main Information: https://yarnpkg.com/advanced/rulebook#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies

https://yarnpkg.com/getting-started/migration#fix-dependencies-with-packageextensions

and

https://yarnpkg.com/getting-started/migration#a-package-is-trying-to-access-another-package-

@jaywcjlove
Copy link
Member

@bradennapier How should I fix it to support yarn 2?

@data-enabler
Copy link

I'm also encountering this issue while trying to migrate from npm to pnpm, which treats dependencies in a similarly strict fashion.

Like @bradennapier said, modules directly imported from this library need to be included as a dependency in your package.json file.

@jaywcjlove
Copy link
Member

@data-enabler This issue has been resolved.

@doubleforte
Copy link

I believe this commit is actually breaking my jest tests. "SyntaxError: Cannot use import statement outside a module"

The previous version of react-md-editor (3.23.3) did not have a /node_modules/@uiw/react-markdown-preview/node_modules directory, but this update (3.23.4) does and it contains refractor and rehype-prism-plus. If I manually delete that directory, my tests pass. Clearly, that's not the right way to do it. :)

Also of note: /node_modules/@uiw/react-markdown-preview/package.json specifies "rehype-prism-plus": "~1.5.0" and /node_modules/@uiw/react-md-editor/package.json (which I believe is the troublemaker?) specifies "rehype-prism-plus": "~1.6.1"

Maybe it's a version mismatch, maybe something else.

I'm on Yarn v1.22.19.

jaywcjlove added a commit to uiwjs/react-markdown-preview that referenced this issue Aug 2, 2023
github-actions bot added a commit to uiwjs/react-markdown-preview that referenced this issue Aug 2, 2023
jaywcjlove added a commit that referenced this issue Aug 2, 2023
@jaywcjlove
Copy link
Member

@bradennapier Synchronized the version of rehype-prism-plus.

github-actions bot added a commit that referenced this issue Aug 2, 2023
@doubleforte
Copy link

@bradennapier Synchronized the version of rehype-prism-plus.

Worked great! Thank you!

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

No branches or pull requests

4 participants