Closed jarkin13 closed 10 months ago
Can you provide a complete reproduction? Nothing looks problematic from Microbundle's side from what I see. This might be an issue better solved in Webpack's repo.
Closing, happy to reopen if you can provide a reproduction but this doesn't seem like an issue on our side.
I am developing a node module that will be consumed by applications that use Webpack(more specifically CRA and CRACO to build) and Next.js. The node module uses
microbundle
when building and publishing the module.The module imports a 3rd party library and uses a different URL based on the environment. Ideally, I would like the application consuming our module to pass a host for the 3rd party library. However, using any conditionals or passing any variables as the host causes the following error:
Error: Cannot find module https://example.com/library.
Using
tsc
to build my module all of the solutions below work, butmicrobundle
does something with dynamic imports causing the error.This works
Imports that cause an error
I am not using the
importLibrary
function directly in the consuming applications. I have a hook that imports the library and passes theenv
orhost
to the function from the consuming application.If the node module is used in a vite application, all solutions above work.
In addition, I am simplifying my code, the actual code I am using does have a try statement. I do console.log the error and return undefined if it can't be imported.