developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8k stars 361 forks source link

[help] - Rollup failed to resolve import "react" from Vite #1028

Closed giacomorebonato closed 1 year ago

giacomorebonato commented 1 year ago

I made a React component and I am doing the build with Microbundle. Everything works OK in dev.

To test it out I created also an example in the same repo. https://github.com/giacomorebonato/wysiwyg-markdown-react

The example is created with Vite, which as I said works well when I do pnpm dev, but it fails with the following error when doing pnpm build

│ [vite]: Rollup failed to resolve import "react" from "/Users/<me>/Code/wysiwyg-markdown-react/packages/markdown-editor/dist/wysiwyg-ma
│ This is most likely unintended because it can break your application at runtime.

Do you think that I am in the right place to ask for help? I am wondering if it is a Vite issue, which in theory should bring in React, but I am not sure at this point

The steps for reproducing the issues are

git clone https://github.com/giacomorebonato/wysiwyg-markdown-react.git
pnpm i
pnpm -r build
rschristian commented 1 year ago

My (quick) guess would be that it's a workspaces + Vite issue.

You could try adding react as a dev dependency of your library. This won't affect Microbundle/your output at all, but what I'm guessing is going on is Vite is attempting to resolve react through packages/markdown-editor, and PNPM hasn't set up proper links for react as it's not listed as a dependency in your library.

giacomorebonato commented 1 year ago

That worked indeed. Thank you!