salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.62k stars 394 forks source link

SSR compiled modules expect to have access to @lwc/ssr-runtime #4554

Open lpomerleau opened 2 days ago

lpomerleau commented 2 days ago

Description

Steps to Reproduce

See lwc#2400 here.

In this PR, we are integrating the @lwc/ssr-compiler into LWR-Node for TD-0205202. We started passing TransformOptions.targetSSR = true into @lwc/compiler#transformSync.

  1. Clone the lwr repo
  2. Checkout the laura/ssr-compiler branch
  3. yarn (install + build)
  4. yarn ssr:start
  5. Visit http://localhost:4000

Expected Results

The @lwc/ssr-runtime is found. It replaces the lwc imports during SSR compilation here.

Actual Results

The LWR-Node runtime cannot find the @lwc/ssr-runtime package when bundling an SSR-compiled LWC:

[error] 404: Could not find module entry with specifier "@lwc/ssr-runtime"

Note: this error may be buried under another error: https://github.com/salesforce/lwc/issues/4555

Browsers Affected

Node.js

Version

Node project package.json "peerDependencies": { "@lwc/compiler": ">= 2.x" } "devDependencies": { "@lwc/compiler": "7.2.6" }

Possible Solution

In LWR-Node, we set lwc as a peer dependency which is met by the app layer. Does the same approach need to be taken with @lwc/ssr-runtime to support SSR-compiled modules?

nolanlawson commented 2 days ago

So currently the lwc package does not export @lwc/ssr-compiler or @lwc/ssr-runtime. You can see its exported packages here: https://github.com/salesforce/lwc/tree/master/packages/lwc

I think we could definitely do this, but probably not until @lwc/ssr-* is ready for prime time.

In the meantime, yes, you would need to set it as a peer dependency. This is probably a good practice anyway, because transitive dependencies are not always allowed to be imported/required at the top level (I believe some versions of Yarn disallow this).

nolanlawson commented 2 days ago

Alternatively, we can just re-export these from the lwc package right now if this is a big blocker.