Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong package exports #3112

Open
userquin opened this issue Jan 16, 2025 · 11 comments
Open

wrong package exports #3112

userquin opened this issue Jan 16, 2025 · 11 comments
Labels
bug Something isn't working v3 #1289

Comments

@userquin
Copy link
Member

userquin commented Jan 16, 2025

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:

/cc @danielroe

Additional context

No response

Logs

@userquin userquin added bug Something isn't working triage v3 #1289 labels Jan 16, 2025
@benjamincanac
Copy link
Member

What issue do you encounter exactly? The exports to .d.mts will be used once we migrate to new major of @nuxt/module-builder.

@danielroe
Copy link
Member

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

Copy link
Member

What are the benefits? 🤔

@danielroe
Copy link
Member

danielroe commented Jan 16, 2025

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!

@benjamincanac
Copy link
Member

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

@userquin
Copy link
Member Author

I can send a PR

@userquin
Copy link
Member Author

userquin commented Jan 24, 2025

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",

@benjamincanac
Copy link
Member

@userquin Do you plan to send a PR?

@userquin
Copy link
Member Author

userquin commented Mar 4, 2025

yes, but I still cannot build the repo on my local, my pr merged at nuxt-component-meta but not released yet:
nuxtlabs/nuxt-component-meta#77

@sandros94
Copy link
Member

@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 #3479 later today or upcoming days

Copy link
Member

Closing this as it should have been fixed by #3799. Feel free to reopen if I misunderstood the issue.

@benjamincanac benjamincanac removed the triage label Apr 8, 2025 — with Volta.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v3 #1289
Projects
None yet
Development

No branches or pull requests

4 participants