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

support package.json "exports" #37

Open
chase-moskal opened this issue Nov 7, 2023 · 3 comments
Open

support package.json "exports" #37

chase-moskal opened this issue Nov 7, 2023 · 3 comments

Comments

@chase-moskal
Copy link
Owner

i think importly currently only works with the "main" field, eg, "main": "./x/index.js" — iirc, we also support "module" field...

we really should add support all this newfangled "exports" field

i'm pretty sure importly will fail to provide a correct importmap for packages that are using this standard..

amazingly, despite it apparently being around since node 12, i haven't personally encountered this problem in the wild yet, but i recently learned about tsconfig nodenext, and that led to this, so i've been thinking about this lately..

five minutes later...

yikes, there's also all this crazy "imports" field stuff too...
do we need this also? i mean there's #dep syntax and wildcards/*.js 😱

why did they have to do this to me? 💀

i think i'm going to ignore and procrastinate this issue until the exact last microsecond before some important package i rely on forces me to implement this in order to use it. for now, i'll stick to "main", and for anything outside that, i'll reference the damn .js manually..

eg, @benev/construct/mini might have to be @benev/construct/x/mini.js as a workaround...

meanwhile, if any damn package in my dependency graph requires the funky "import" field mappings in order to work, everything will explode... yikes man.. you know, the nodejs team better have made library that can magically handle all this funky stuff or my head will explode..

lukeed's resolve.exports!! 👏 👏

configurable "exports" and "imports" resolver

hell yeah!! it even does the imports!?!?! 😎 😎

if this fella did this not in an official capacity for the nodejs team — then that's negligent malpractice on node's part — and this guy deserves a gold medal and a briefcase full of money 😆

@chase-moskal
Copy link
Owner Author

yo, i think i also need to add support for browser package.json field https://docs.npmjs.com/cli/v10/configuring-npm/package-json#browser

@chase-moskal
Copy link
Owner Author

linked issue about browser field support in import maps WICG/import-maps#296

@chase-moskal
Copy link
Owner Author

fyi, we encountered a package in the wild that uses this fancy export stuff (which importly doesn't currently support)

@ffmpeg/ffmpeg — you can see in their package.json

  "exports": {
    ".": {
      "types": "./dist/esm/index.d.ts",
      "node": "./dist/esm/empty.mjs",
      "default": {
        "import": "./dist/esm/index.js",
        "require": "./dist/umd/ffmpeg.js"
      }
    }
  },

so the current workaround, to get your app working now, is to manually directly import the es module in your app:

import {FFmpeg} from "@ffmpeg/ffmpeg/dist/esm/index.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant