wrong package exports
Environment
NA
Is this bug related to Nuxt or Vue?
Nuxt
Version
v3.0.0-alpha
Reproduction
NA: check the package.json file
Description
The package exports using .d.ts instead d.mts. #imports should also be reviewed, for example we should add #build/ui.
For reference:
- https://github.com/nuxt/nuxt/pull/30148
- https://github.com/nuxt/nuxt/pull/30206
/cc @danielroe
Additional context
No response
Logs
What issue do you encounter exactly? The exports to .d.mts will be used once we migrate to new major of @nuxt/module-builder.
@benjamincanac you can already adopt them before the module builder upgrade, if you want
What are the benefits? 🤔
It's more correct. If it's well set up, it means the types users can see in their projects is consistent across node10/node16 module resolutions modes + ESM/CJS.
You can see the results here: https://arethetypeswrong.github.io/?p=@nuxt/[email protected]
Nuxt modules don't need to be imported in CJS so that row is less important. Some of the other columns are failing due to imports (like #app) that can't be resolved, so the picture isn't as dire as it might seem!
@danielroe Do you have any guidelines to make the switch?
I can send a PR
Following changes using Nuxt with ESM only and dual CJS/ESM for vite and unplugin (without Node10 types support). You can check for example https://github.com/vite-pwa/nuxt/blob/main/package.json
I've also included "#build/ui": "./.nuxt/ui/index.ts", at #imports on my local (not included in the patch bellow):
"imports": {
"#build/ui": "./.nuxt/ui/index.ts",
"#build/ui/*": "./.nuxt/ui/*.ts"
},
We also need to check why we're exporting runtime types from the module, this is breaking Windows build since .vue files cannot be resolved. vite and unplugin modules importing types from the module (ModuleOptions) and from #build/ui (import type * as ui from '#build/ui'), maybe we can split the types since the ModuleOptions is only required when building the module, for example creating types.ts (ModuleOptions => NuxtUIOptions) and exporting configuration types there => the module will just use export interface ModuleOptions extends NuxtUIOptions { /* some nuxt stuff if required */ }.
NOTE: since I cannot build Nuxt UI on my Windows laptop I cannot test it, I just downloaded latest tarball file and patched it manually.
Upps, you can ignore this change:
"build": "nuxt-module-build build && pnpm devtools:build",
+ "build:module": "nuxt-module-build build",
Subject: [PATCH] fix package export
---
Index: package.json
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/package.json b/package.json
--- a/package.json (revision 51e5e65be7f834ec226be28d95a1b547b85b329c)
+++ b/package.json (date 1737720287506)
@@ -12,18 +12,15 @@
"license": "MIT",
"exports": {
".": {
- "types": "./dist/module.d.ts",
+ "types": "./dist/types.d.mts",
"style": "./dist/runtime/index.css",
- "import": "./dist/module.mjs",
- "require": "./dist/module.cjs"
+ "default": "./dist/module.mjs"
},
"./unplugin": {
- "types": "./dist/unplugin.d.ts",
"import": "./dist/unplugin.mjs",
"require": "./dist/unplugin.cjs"
},
"./vite": {
- "types": "./dist/vite.d.ts",
"import": "./dist/vite.mjs",
"require": "./dist/vite.cjs"
},
@@ -43,7 +40,7 @@
"nuxt-ui": "./cli/index.mjs"
},
"style": "./dist/runtime/index.css",
- "main": "./dist/module.cjs",
+ "main": "./dist/module.mjs",
"types": "./dist/types.d.ts",
"files": [
".nuxt/ui",
@@ -53,6 +50,7 @@
],
"scripts": {
"build": "nuxt-module-build build && pnpm devtools:build",
+ "build:module": "nuxt-module-build build",
"prepack": "pnpm build",
"dev": "DEV=true nuxi dev playground",
"dev:vue": "DEV=true vite playground-vue",
@userquin Do you plan to send a PR?
yes, but I still cannot build the repo on my local, my pr merged at nuxt-component-meta but not released yet: https://github.com/nuxtlabs/nuxt-component-meta/pull/77
@userquin we got a new release for [email protected]. If it is ok for you I would like to test it and fix this in https://github.com/nuxt/ui/pull/3479 later today or upcoming days
Closing this as it should have been fixed by https://github.com/nuxt/ui/pull/3799. Feel free to reopen if I misunderstood the issue.