Installing module from npm causes does not provide an export named 'default' issue
Hello! First of all here is the error:
I'm trying to create the nuxt module for Scalar API References. You can find the code for the module here: https://github.com/scalar/scalar/tree/main/packages/nuxt. It works fine in the playground and when I'm testing. However when I either use
pnpm pack
or release the package to NPM and install it a fresh Nuxt app, it gives me this error. Also the error does not exist in prod, its only in development. I looked into the debug package and it does not support esm at all. Now I'm not sure how its working in the playground, not to mention in the countless esm apps the depend on it.
Am I missing something in the build config? I tried with and without that transpiling and it has the same issue. Also I have been manually releasing to npm as well as testing with pnpm pack, our CI isn't setup for nuxt modules quite yet.3 Replies
Adding the module code here:
You can check it out in a stackblits here https://stackblitz.com/edit/nuxt-starter-ej8m1z?file=package.json,nuxt.config.ts
StackBlitz
Nuxt Scalar API References Starter Amrit testing - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
So it looks like I need to use build.config.ts, though not quite sure what I'm missing here
if I set
stub:true
it works, but all my paths become hard paths from my machine. Is there any way to avoid that? Maybe this belongs under unjs
?
hmm maybe the issue is actually that vite is not optimizing this dependency
Alright so I ended up placing it in the module.ts file setup function and it works!