Nuxt Moudle Con't run "dev:prepare"

package.json
"dependencies": {
"@nuxt/kit": "^4.0.3",
"shiki": "^3.12.1"
},
"devDependencies": {
"@nuxt/eslint-config": "^1.9.0",
"@nuxt/module-builder": "^1.0.2",
"@nuxt/schema": "^4.0.3",
"@nuxt/test-utils": "^3.19.2",
"@types/bun": "^1.2.21",
"changelogen": "^0.6.2",
"eslint": "^9.34.0",
"nuxt": "^4.0.3",
"sass": "^1.91.0",
"sass-embedded": "^1.91.0",
"typescript": "^5.1.6",
"vitest": "^3.2.4"
},
"dependencies": {
"@nuxt/kit": "^4.0.3",
"shiki": "^3.12.1"
},
"devDependencies": {
"@nuxt/eslint-config": "^1.9.0",
"@nuxt/module-builder": "^1.0.2",
"@nuxt/schema": "^4.0.3",
"@nuxt/test-utils": "^3.19.2",
"@types/bun": "^1.2.21",
"changelogen": "^0.6.2",
"eslint": "^9.34.0",
"nuxt": "^4.0.3",
"sass": "^1.91.0",
"sass-embedded": "^1.91.0",
"typescript": "^5.1.6",
"vitest": "^3.2.4"
},
tsconfig.json
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ESNext", "DOM"],
"types": ["bun"]
}
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ESNext", "DOM"],
"types": ["bun"]
}
error log
Run bun run dev:prepare
$ nuxt-module-build build --stub && nuxi prepare playground
Error: Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'typescript';
const { convertCompilerOptionsFromJson } = pkg;
import { convertCompilerOptionsFromJson } from 'typescript';
^
SyntaxError: Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'typescript';
const { convertCompilerOptionsFromJson } = pkg;
..
Error: Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'typescript';
const { convertCompilerOptionsFromJson } = pkg;
error: script "dev:prepare" exited with code 1
Run bun run dev:prepare
$ nuxt-module-build build --stub && nuxi prepare playground
Error: Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'typescript';
const { convertCompilerOptionsFromJson } = pkg;
import { convertCompilerOptionsFromJson } from 'typescript';
^
SyntaxError: Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'typescript';
const { convertCompilerOptionsFromJson } = pkg;
..
Error: Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'typescript';
const { convertCompilerOptionsFromJson } = pkg;
error: script "dev:prepare" exited with code 1
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
kapa.ai
kapa.ai2d ago
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:
Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
Named export 'convertCompilerOptionsFromJson' not found. The requested module 'typescript' is a CommonJS module, which may not support all module.exports as named exports.
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:
import { convertCompilerOptionsFromJson } from 'typescript'

import { convertCompilerOptionsFromJson } from 'typescript'

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:
import pkg from 'typescript'
const { convertCompilerOptionsFromJson } = pkg

import pkg from 'typescript'
const { convertCompilerOptionsFromJson } = pkg

- 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: ----------------------
kapa.ai
kapa.ai2d ago
<@370382517720580099> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?