ui icon indicating copy to clipboard operation
ui copied to clipboard

wrong package exports

Open userquin opened this issue 1 year ago • 11 comments

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


userquin avatar Jan 16 '25 11:01 userquin

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 avatar Jan 16 '25 11:01 benjamincanac

@benjamincanac you can already adopt them before the module builder upgrade, if you want

danielroe avatar Jan 16 '25 17:01 danielroe

What are the benefits? 🤔

benjamincanac avatar Jan 16 '25 18:01 benjamincanac

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 avatar Jan 16 '25 23:01 danielroe

@danielroe Do you have any guidelines to make the switch?

benjamincanac avatar Jan 24 '25 11:01 benjamincanac

I can send a PR

userquin avatar Jan 24 '25 12:01 userquin

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 avatar Jan 24 '25 12:01 userquin

@userquin Do you plan to send a PR?

benjamincanac avatar Mar 04 '25 10:03 benjamincanac

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 avatar Mar 04 '25 13:03 userquin

@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

sandros94 avatar Mar 25 '25 12:03 sandros94

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.

benjamincanac avatar Apr 08 '25 09:04 benjamincanac