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

SvelteKit fails build due to library using "exports" block with "." and import and require entries #2639

Closed
TeemuKoivisto opened this issue Oct 19, 2021 · 1 comment

Comments

@TeemuKoivisto
Copy link

Describe the bug

Since my last bug report was little hastily conjured, I tried to take time with this. However, it seems there is a bug with SvelteKit's build process. Basically what happens is that I'm using a library that defines exports block with the values:

  "exports": {
    "./package.json": "./package.json",
    ".": {
      "import": "./src/y-websocket.js",
      "require": "./dist/y-websocket.cjs"
    }
  },

When I try to run svelte-kit build it somehow resolves the "import" entry as CJS. Deleting this block and letting the library be resolved with "main" and "module" entries fixes it so I think there's something wrong here. I added Rollup and Vite bundling of the same library which do resolve it correctly using "exports".

screenshot

Reproduction

https://github.com/TeemuKoivisto/exports-import-not-es-module

Logs

No response

System Info

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 229.87 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 16.11.1 - ~/.nvm/versions/node/v16.11.1/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v16.7.0/bin/yarn
    npm: 8.0.0 - ~/.nvm/versions/node/v16.11.1/bin/npm
  Browsers:
    Chrome: 94.0.4606.81
    Firefox: 92.0.1
    Safari: 13.1.3
  npmPackages:
    @sveltejs/adapter-static: ^1.0.0-next.21 => 1.0.0-next.21 
    @sveltejs/kit: ^1.0.0-next.186 => 1.0.0-next.186 
    svelte: ^3.44.0 => 3.44.0

Severity

blocking an upgrade

Additional Information

No response

@bluwy
Copy link
Member

bluwy commented Oct 19, 2021

The issue is in y-websocket, it exports:

"exports": {
    "./package.json": "./package.json",
    ".": {
      "import": "./src/y-websocket.js",
      "require": "./dist/y-websocket.cjs"
    }
  },

Note the .js and .cjs. These extensions combo are usually used when the package.json is type: "module", but it's not. What it should be instead is .mjs and .js, since that's how node detects the file format (ESM or CJS). If they want to stick with the extensions they have now, they need to use type: "module".

There seems to be a similar issue there yjs/y-websocket#72, so I'm closing this in favor of that.

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

No branches or pull requests

2 participants