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

export map sub condition object keys with a wildcard are not resolving in the browser (condition not getting expanded) #1397

Closed
thescientist13 opened this issue Jan 25, 2025 · 1 comment · Fixed by #1398
Assignees
Labels
alpha.6 bug Something isn't working CLI v0.31.0
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Jan 25, 2025

Type of Change

Bug

Summary

As reported in Discord, a user was trying to use the signals-utils package and was getting this error in the browser

import { SignalObject } from 'signal-utils/object';

Image

With this as the generated import map entries, where we can see the wildcards are not getting "expanded"

it recommends signal-utils but some of the imports from that npm, such as import { SignalObject } from 'signal-utils/object'; hit more odd import map behaviors. but if I just define single signals for each property instead of a reactive object, I can import it as import * as stores from ...then itsstores..get()and .set()` which is close enough.

{
  "signal-utils": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/index.ts.js",
  "signal-utils/*": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/*.ts.js"
}

Repro repo is here - https://github.com/thescientist13/greenwood-lit-ssr/tree/signals-wildcard-sub-condition

Details

Looking into a bit further, it seems to be an oversight in our export conditions logic where-in with an export map like so
https://unpkg.com/browse/[email protected]/package.json

 "exports": {
    ".": {
      "types": "./declarations/index.d.ts",
      "default": "./dist/index.ts.js"
    },
    "./*": {
      "types": "./declarations/*.d.ts",
      "default": "./dist/*.ts.js"
    }
  },

We are missing tracking for wildcards
https://github.com/ProjectEvergreen/greenwood/blob/v0.31.0-alpha.5/packages/cli/src/lib/walker-package-ranger.js#L182

Which we do with non-object conditions
https://github.com/ProjectEvergreen/greenwood/blob/v0.31.0-alpha.5/packages/cli/src/lib/walker-package-ranger.js#L196


Somewhat related, but one of the issues this package possibly introduces is that the when we try to map ./* we are getting extensions on the left hand side, although the usage details don't assume that, e.g.

# does not work
import { SignalObject } from 'signal-utils/object';

# works
import { SignalObject } from 'signal-utils/object.ts.js';
    "signal-utils": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/index.ts.js",
  "signal-utils/array-map.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/array-map.ts.js",
  "signal-utils/array.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/array.ts.js",
  "signal-utils/async-computed.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/async-computed.ts.js",
  "signal-utils/async-data.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/async-data.ts.js",
  "signal-utils/async-function.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/async-function.ts.js",
  "signal-utils/dedupe.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/dedupe.ts.js",
  "signal-utils/deep.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/deep.ts.js",
  "signal-utils/index.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/index.ts.js",
  "signal-utils/local-copy.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/local-copy.ts.js",
  "signal-utils/map.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/map.ts.js",
  "signal-utils/object.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/object.ts.js",
  "signal-utils/promise.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/promise.ts.js",
  "signal-utils/set.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/set.ts.js",
  "signal-utils/weak-map.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/weak-map.ts.js",
  "signal-utils/weak-set.ts.js": "/~/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/[email protected][email protected]/node_modules/signal-utils/dist/weak-set.ts.js"
  

Interestingly, Node seems to detect this just fine? If adding .ts.js we get an SSR error 🤔

node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/signal-utils/dist/object.ts.js.ts.js' imported from /Users/owenbuckley/Workspace/github/greenwood-lit-ssr/src/components/card.ts
    at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:932:10)
    at defaultResolve (node:internal/modules/esm/resolve:1056:11)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at resolve (file:///Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/.pnpm/@[email protected]_patch_hash=apevrozsvdlx72kzhcuzdsx7pm/node_modules/@greenwood/cli/src/loader.js:91:10)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
    at handleMessage (node:internal/modules/esm/worker:199:24)
    at Immediate.checkForMessages (node:internal/modules/esm/worker:141:28)
    at process.processImmediate (node:internal/timers:491:21) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///Users/owenbuckley/Workspace/github/greenwood-lit-ssr/node_modules/signal-utils/dist/object.ts.js.ts.js'
}
@thescientist13 thescientist13 added bug Something isn't working CLI v0.31.0 labels Jan 25, 2025
@thescientist13 thescientist13 added this to the 1.0 milestone Jan 25, 2025
@thescientist13 thescientist13 self-assigned this Jan 25, 2025
@thescientist13 thescientist13 changed the title export maps sub condition object key with a wildcard are not resolving in the browser export maps sub condition object keys with a wildcard are not resolving in the browser (condition not getting expanded) Jan 25, 2025
@thescientist13 thescientist13 changed the title export maps sub condition object keys with a wildcard are not resolving in the browser (condition not getting expanded) export map sub condition object keys with a wildcard are not resolving in the browser (condition not getting expanded) Jan 25, 2025
@thescientist13 thescientist13 moved this from 🔖 Ready to 🏗 In progress in [Greenwood] Phase 10 - Ecosystem Compat Jan 25, 2025
@lschierer
Copy link
Contributor

Interestingly, Node seems to detect this just fine? If adding .ts.js we get an SSR error

I did say it was an odd error ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
alpha.6 bug Something isn't working CLI v0.31.0
Projects
Development

Successfully merging a pull request may close this issue.

2 participants