Nuxt Moudle Con't run "dev:prepare"
package.json
tsconfig.json
error log
It was working fine.
After the error occurred, I tried adding "moduleResolution": "bundler" to tsconfig.json, but it's still not working.
What should I check?2 Replies
Hi @Lovefield. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error you are encountering:
indicates an ESM/CommonJS interop issue with the TypeScript package. This is a known problem when using ESM-based tools (like Bun or modern Nuxt) with a CommonJS build of TypeScript, especially when using named imports.
What’s Happening?
- Your
typescript
dependency is likely being resolved as a CommonJS module, but your environment (Bun, ESM, or a tool using ESM imports) expects it to provide named exports, which CommonJS does not natively support.
- The error message suggests that the code is trying to do:
but in CommonJS, this is not available as a named export.
What Should You Check?
1. TypeScript Version and Module Format
- Ensure you are using a TypeScript version that provides ESM support. However, as of now, the official TypeScript package on npm is still published as CommonJS, not ESM, which can cause issues in ESM environments like Bun or when using "moduleResolution": "bundler"
.
2. Transpiling or Aliasing TypeScript
- You may need to alias or transpile the TypeScript package to ensure compatibility. The Nuxt docs suggest that, for similar ESM/CJS issues, you can alias the dependency to a compatible version or use the default export pattern:
- However, if the tool you are using (like nuxt-module-build
or nuxi
) is importing TypeScript as an ESM module, you cannot easily change this import style yourself.
3. Check for Upstream Fixes or Issues
- This is a known ecosystem issue. The Nuxt docs recommend checking if the upstream library (in this case, the tool or module that imports TypeScript) has a fix or workaround for ESM environments. If not, you may need to wait for an update or use Node.js instead of Bun for this step, as Node.js has better interop for CommonJS modules in ESM contexts What Kinds of Problems Can There Be? | Troubleshooting ESM Issues.
4. Try Node.js Instead of Bun
- If you are running bun run dev:prepare
, try running the same command with Node.js. Bun’s ESM support is still evolving and may not handle CommonJS interop as robustly as Node.js.
5. Check for Module Updates
- Make sure all your Nuxt-related packages (@nuxt/kit
, @nuxt/module-builder
, etc.) are up to date and compatible with your Nuxt version.
Summary
- This is a CommonJS/ESM interop issue with the TypeScript package.
- Bun may not handle this interop as well as Node.js.
- Try running your command with Node.js.
- If you must use Bun, check if there are updates or workarounds in the Nuxt or Bun communities.
- You cannot fix this by changing tsconfig.json
options alone.
For more details on ESM/CJS interop issues and troubleshooting, see the Nuxt documentation: Troubleshooting ESM Issues.
If the problem persists, you may need to wait for upstream fixes or use Node.js for development tasks that require TypeScript interop.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@370382517720580099> Kapa.ai is still learning and improving, please let me know how I did by reacting below.