Skip to content

Multi level "exports" not supported? #250

Closed
@achingbrain

Description

@achingbrain

The multiformats module has the following fields in it's package.json:

{
  // ...other stuff
  "main": "./cjs/src/index.js",
  "browser": {
    ".": "./cjs/src/index.js",
    "./basics": "./cjs/src/basics.js",
    "./bases/base16": "./cjs/src/bases/base16.js"
    // ...other stuff
  },
  "exports": {
    ".": {
      "browser": "./esm/src/index.js",
      "require": "./cjs/src/index.js",
      "import": "./esm/src/index.js"
    },
    "./basics": {
      "browser": "./esm/src/basics.js",
      "require": "./cjs/src/basics.js",
      "import": "./esm/src/basics.js"
    },
    "./bases/base16": {
      "browser": "./esm/src/bases/base16.js",
      "require": "./cjs/src/bases/base16.js",
      "import": "./esm/src/bases/base16.js"
    }
    // ...other stuff
  }
}

and the following directory structure:

multiformats
|-- cjs
|    +-- src
|         |-- index.js
|         |-- basics.js
|         +-- bases
|              +-- base16.js
|-- esm
|    +-- src
|         |-- index.js
|         |-- basics.js
|         +-- bases
|              +-- base16.js
|-- src
|    |-- index.js
|    |-- basics.js
|    +-- bases
|         +-- base16.js

When using browserify on a project that depends on multiformats, I see errors when trying to require anything greater than one level deep in the module:

const mf = require('multiformats')
// ok
const basics = require('multiformats/basics')
// ok
const basics = require('multiformats/basics/base16')
// Error: Can't walk dependency graph: Cannot find module 'multiformats/bases/base16' from '/path/to/index.js'
//     required by /path/to/index.js
//     at /path/to/node_modules/resolve/lib/async.js:137:35
//     at processDirs (/path/to/node_modules/resolve/lib/async.js:291:39)
//     at isdir (/path/to/node_modules/resolve/lib/async.js:300:32)
//     at /path/to/node_modules/resolve/lib/async.js:25:69
//     at FSReqCallback.oncomplete (fs.js:183:21)

Is this intentional? I can't see where this module consults the exports field (though it's been a long day) or is it unsupported?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions