Skip to content

Nested conditional exports in package.json not supported #1793

@akapug

Description

@akapug

Summary

Elide doesn't support nested conditional exports in package.json, which prevents many popular npm packages from loading.

Reproduction

// test.ts
import { Collection } from '@discordjs/collection';
console.log(Collection);
npm install @discordjs/collection
elide run test.ts
# Error: Unsupported package exports: ''

Package.json exports that fail

{
  "exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.mts",
        "default": "./dist/index.mjs"
      },
      "require": {
        "types": "./dist/index.d.ts", 
        "default": "./dist/index.js"
      }
    }
  }
}

Package.json exports that work

{
  "exports": {
    ".": {
      "types": "./lib/main.d.ts",
      "require": "./lib/main.js",
      "default": "./lib/main.js"
    }
  }
}

Expected behavior

Elide should resolve nested conditional exports per the Node.js package exports spec.

For ESM imports, it should resolve:

  1. Check exports["."]
  2. Check exports["."].import (since we're using ESM)
  3. Use exports["."].import.default

Affected packages

Many packages in the discord.js ecosystem use this pattern:

  • @discordjs/collection
  • @discordjs/rest
  • @discordjs/ws
  • @discordjs/builders
  • discord.js itself

Workaround

Currently using esbuild to bundle dependencies, which resolves the exports correctly before Elide sees them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:nodeNode API and stdliblang:javascriptIssues relating to JavaScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions