N
Nuxt3d ago
Alchez

Nuxt Module Builder Issue

Whenever I run the nuxt-module-build build command inside my package, I get the following error in one of the build outputs:
ℹ Building nuxt 11:39:49 AM
ℹ Cleaning dist directory: ./dist 11:39:49 AM
.nuxt/components.plugin.mjs(3,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '~/node_modules/nuxt/dist/app/nuxt.js'. This is likely not portable. A type annotation is necessary.


ERROR Failed to compile. Check the logs above. 11:39:53 AM

at error (/common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
at Object.error (/common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:25351:20)
at Object.error (/common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24472:42)
at generateDtsFromTs (/common/temp/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1834:30)
at Object.transform (/common/temp/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1843:38)
at /common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:25544:40
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)



ERROR Failed to compile. Check the logs above.
ℹ Building nuxt 11:39:49 AM
ℹ Cleaning dist directory: ./dist 11:39:49 AM
.nuxt/components.plugin.mjs(3,1): error TS2742: The inferred type of 'default' cannot be named without a reference to '~/node_modules/nuxt/dist/app/nuxt.js'. This is likely not portable. A type annotation is necessary.


ERROR Failed to compile. Check the logs above. 11:39:53 AM

at error (/common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:2287:30)
at Object.error (/common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:25351:20)
at Object.error (/common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:24472:42)
at generateDtsFromTs (/common/temp/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1834:30)
at Object.transform (/common/temp/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.mjs:1843:38)
at /common/temp/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:25544:40
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)



ERROR Failed to compile. Check the logs above.
I'm creating a Nuxt module inside a Rushstack monorepo.
5 Replies
kapa.ai
kapa.ai3d ago
Hi @Alchez. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, I don't have enough specific details to directly address the issue you're experiencing with the Nuxt Module Builder in a Rushstack monorepo. The error you're encountering is not explicitly covered in the provided documents. However, I can offer some general insights and suggestions based on related information: 1. The error message suggests a TypeScript compilation issue, specifically related to type inference and portability. This could be due to how your module is structured or how it's referencing Nuxt types. 2. Since you're working in a monorepo, there might be some complexities with how dependencies are resolved or how TypeScript is configured across your project. 3. To troubleshoot this issue, you might want to: - Check your tsconfig.json file to ensure it's properly configured for a Nuxt module. As mentioned in the TypeScript documentation for Nuxt Bridge, you might need to extend the Nuxt-generated TypeScript configuration:
{
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
...
}
}

{
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
...
}
}

- Ensure that your module's dependencies, particularly Nuxt and TypeScript-related ones, are correctly specified and installed. - Review how you're importing and using Nuxt types in your module code. The error suggests there might be an issue with how these are being referenced. 4. If the issue persists, you might want to create a minimal reproduction of the problem and report it as a potential bug. The Nuxt community guide on reporting bugs provides helpful steps for this process. 5. Additionally, since you're using the Nuxt Module Builder, make sure you're following the best practices for creating Nuxt modules as outlined in the Nuxt documentation on modules. If you continue to face issues, consider seeking help through the official Nuxt channels or creating a more detailed bug report with a minimal reproduction of the problem. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@125579228392587264> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Alchez
AlchezOP3d ago
@kapa.ai Here's the reproducible Github repo: https://github.com/agritheory/stonecrop/tree/fix-nuxt-typescript Running rushx build inside the /nuxt folder should reproduce the issue. Setting the typescript dependency to ~5.6.3 doesn't generate an error.
GitHub
GitHub - agritheory/stonecrop at fix-nuxt-typescript
Schema-driven UI. Contribute to agritheory/stonecrop development by creating an account on GitHub.
kapa.ai
kapa.ai3d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Thank you for providing the reproducible GitHub repository. After reviewing the information in the knowledge sources and your specific issue, I can offer some insights and a potential solution. The error you're encountering seems to be related to TypeScript version compatibility. This aligns with some recent changes and issues in the Nuxt ecosystem. Here's what I found: 1. TypeScript Version: As you mentioned, setting the TypeScript version to ~5.6.3 resolves the issue. This is consistent with a known compatibility problem between Nuxt and newer TypeScript versions. 2. Nuxt TypeScript Support: According to the Nuxt Configuration documentation, Nuxt has built-in TypeScript integration. However, there have been some recent changes that affect TypeScript compatibility. 3. Recent Changes: A recent pull request chore(deps): update devdependency typescript to v5.5.3 (3.x) updated the TypeScript version in Nuxt. This update might be related to the issue you're experiencing. 4. Compatibility Issues: There's an ongoing discussion about TypeScript compatibility in Nuxt. A recent issue Array type not correctly narrowed mentions problems with TypeScript strict mode and version compatibility. Based on these findings, here are some recommendations: 1. Pin TypeScript Version: As you've discovered, pinning the TypeScript version to ~5.6.3 in your package.json resolves the issue. This is a valid temporary solution. 2. Update Nuxt Configuration: You might want to try adjusting your nuxt.config.ts file to include TypeScript-related settings. For example:
export default defineNuxtConfig({
typescript: {
strict: true,
typeCheck: true
}
})

export default defineNuxtConfig({
typescript: {
strict: true,
typeCheck: true
}
})

3. Monitor Nuxt Updates: Keep an eye on Nuxt updates, as this issue might be resolved in future versions. The Nuxt team is actively working on improving TypeScript support and compatibility. 4. Report the Issue: Consider reporting this specific issue to the Nuxt GitHub repository, as it might help the maintainers address the TypeScript compatibility problem in future releases. For now, the most straightforward solution is to continue using TypeScript version ~5.6.3 until the compatibility issue is resolved in Nuxt or its dependencies. Nuxt Configuration - TypeScript Nuxt GitHub Pull Request - TypeScript Update Nuxt GitHub Issue - TypeScript Compatibility ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@125579228392587264> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?