solidjs/vite-plugin-solid

`ERR_PACKAGE_PATH_NOT_EXPORTED` due to bad assumptions in dependency resolution

Closed this issue · 0 comments

npm init solid repro # use default settings for config prompts
cd repro
npm install
npm install --save-dev cubing
npm run build

Expected: no crrash
Observed: even with no code changes, this runs into:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in [path to project]/node_modules/cubing/package.json

Specifically, the error happens due to this line:

let dir = dirname(require.resolve(dep));

package.json definitely exists in the cubing package. I have two guesses for why this is running into an issue:

Someone is trying to use our library with vite-plugin-solid (cubing/cubing.js#236), and I'd appreciate if you could fix this for them. One fix that worked for me locally is replace the bad line with resolve from node:path:

// Added import
import { resolve } from "node:path";

// Replaced line
dir = dirname(resolve(dep));