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

When the "node" condition path in exports is null vite build will wrongly throw a "No known conditions for" error #18015

Open
7 tasks done
bn-l opened this issue Sep 3, 2024 · 1 comment

Comments

@bn-l
Copy link

bn-l commented Sep 3, 2024

Describe the bug

I am trying to build a project with this line:

import * as ort from "onnxruntime-web/webgl";

when I go to build I get this error:

error during build:
[commonjs--resolver] No known conditions for "./webgl" specifier in "onnxruntime-web" package

The issue is with the exports of this particular package.json (excerpt from original).

!!! Note that the node condition for webgl is null: !!!

{
  "exports": {
      ".": {
        "node": {
          "import": "./dist/ort.node.min.mjs",
          "require": "./dist/ort.node.min.js"
        },
      "./webgl": {
        "node": null,
        "import": "./dist/ort.webgl.min.mjs",
        "require": "./dist/ort.webgl.min.js",
        "types": "./types.d.ts"
      }
}

Vite will error if node:'s value is null. This is strange because it shouldn't be checking this value but going straight to "import": "./dist/ort.webgl.min.mjs",. If I change it to any working path (e.g. "/types.d.ts") then it won't blow up and will correctly resolve to "import": "./dist/ort.webgl.min.mjs",. So this does work:

{
  "exports": {
      ".": {
        "node": {
          "import": "./dist/ort.node.min.mjs",
          "require": "./dist/ort.node.min.js"
        },
      "./webgl": {
        "node": "./types.d.ts",
        "import": "./dist/ort.webgl.min.mjs",
        "require": "./dist/ort.webgl.min.js",
        "types": "./types.d.ts"
      }
}

And if I can stop it from checking the node path initially by swapping the order, then it works also (no build error). Note that "import": "./dist/ort.webgl.min.mjs", is now before "node": null:

{
  "exports": {
      ".": {
        "node": {
          "import": "./dist/ort.node.min.mjs",
          "require": "./dist/ort.node.min.js"
        },
      "./webgl": {
        "import": "./dist/ort.webgl.min.mjs",
        "node": null
        "require": "./dist/ort.webgl.min.js",
        "types": "./types.d.ts"
      }
}

Reproduction

see steps

Steps to reproduce

Add the package:

npm add -D onnxruntime-web

Try importing a nested path:

import * as ort from "onnxruntime-web/webgl";

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
    Memory: 5.33 GB / 15.93 GB
  Binaries:
    Node: 22.7.0 - ~\AppData\Local\Volta\tools\image\node\22.7.0\node.EXE
    npm: 10.8.2 - ~\AppData\Local\Volta\tools\image\node\22.7.0\npm.CMD
    pnpm: 9.7.0 - C:\Program Files\Volta\pnpm.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.3636

Used Package Manager

npm

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Sep 3, 2024

I don't think that's how null works. If you're in node and it matches null, it means that that entrypoint cannot be imported in node. Otherwise, what is the point of "node": null if Vite would skip it anyways? (as in if the field being removed would yield the same result in node).

The use of null is documented in https://nodejs.org/api/packages.html#package-entry-points. If you import it in node and it yields the same result, then I think Vite is implementing this correctly.

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