Closed Devsnapper closed 2 years ago
Please provide a repo that I can just clone containing both the lib and your app. I spent some time trying to piece this together but I could not reproduce the issue.
Something that stands out is the mixing of JSX transforms; there's no good reason to do this and I imagine it could lead to issues. Choose one or other for your lib, not both.
You're also mixing and matching default & named exports. Not sure if this was just a byproduct of pasting into this issue, but it certainly doesn't work if someone copy/pasted your code directly.
Please provide a repo that I can just clone containing both the lib and your app. I spent some time trying to piece this together but I could not reproduce the issue.
Something that stands out is the mixing of JSX transforms; there's no good reason to do this and I imagine it could lead to issues. Choose one or other for your lib, not both.
You're also mixing and matching default & named exports. Not sure if this was just a byproduct of pasting into this issue, but it certainly doesn't work if someone copy/pasted your code directly.
@rschristian please find the url and in the zip there are 2 folder 1.consume which is a client app and 2. lib application
1) Don't mix and match JSX transforms. Pick either the classic or runtime. This means removing --jsxImportSource
or the pragma / pragma frag options.
2) If you're embedding into a React app, you don't want --external none
. This bundles React in with your component, essentially duplicating React within your app. Only use that if you're embedding into a page where React is no available.
There's nothing wrong with Microbundle here, so I'm going to close this out.
Created an example repo for you here: https://github.com/rschristian/dev-phani-react-lib-example
Also, use something like yalc when testing libs locally. It's a lot more robust, and linking locally (as you have) is incredibly error prone in just about every package manager. Most of the time doing that will break your lib, causing duplicate bundles and the like.
@rschristian i checked ur repo and even when i tried that also im getting same issues and is there any pre requirements are there and in the lib.package.js u wrote the dropdown logic and instead in the component and it will be great if the you can make modification to the same repo which i posted . Bcoz in the repo it is having only index.js
I cut everything down to the minimum reproduction, as you should've done to begin with. Please don't throw more files and content than are needed at maintainers, that's part of the debugging process that should be done upfront. It certainly doesn't make a difference to microbundle.
And as I said, I suggest using yalc
. You can find the instructions for the tool in the link I posted above. I believe I accidentally committed the yalc file path in the app's package.json
-- that can just be stripped out.
Regardless, your issue is with testing local modules, not with microbundle. The output from microbundle is correct & working.
Hope that helps.
Hi I am trying to create a sample library using react 18.2.0 and Although library built successfully but when it is consumed in the app im getting the below error in console log
below is my library code
App.js
Created components folder under that created Dropdown.js
in the src folder created the lib.package.js
export { Dropdown } from "./components/Dropdown.js";
below is my package.json
Below is my client app where i am consuming the package
App.js
@developit @rschristian