-
-
Notifications
You must be signed in to change notification settings - Fork 927
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
Importing solid-js/web (as ESM, from Node.js) throws a SyntaxError #1984
Comments
So far we've pushed people to use "browser" export conditions for this. Like in Not sure. What I'm getting at it is this probably won't work correctly for everyone unless we treat it as browser across the board which can only be done through conditions as web internally doesn't wire to browser version of solid etc... It is interesting problem. |
Makes sense. It's pretty tough to hit every usecase gracefully. When reading this section in solid-jest, I noticed that a user can choose the right preset to get what I assume to be the build of Solid that they want. One of the reasons I'm using So, I'm wondering if a similar concept can be applied here. Perhaps by importing something like What do you think? Edit: For additional context, I've found a decent workaround via a custom Node.js loader hook that rewrites imports for A loader hook is a reasonable path, assuming that the test runner in use allows configuring Node.js arguments. |
I am hitting this issue in Vite/Vitest and am still looking for a workaround. Setting |
I think you are going have to depend aliasing then because this is a multi-package concern. While any package could just import from the right source (we expose dist) our core libraries which reference each other would not. Export conditions make sense here or bundler aliasing makes sense here but hard-coding the libraries doesn't particularly. It doesn't really extend out well into the ecosystem either. We tend to ship as source to give maximum compilation flexibility to the end user so like intermediate libraries aren't going to do the combinatorics as well. I think we should look at export conditions here a bit more and see if we can be more helpful in some way. Like we have a "server" export condition when people need that build regardless of node etc.. Maybe there is a way to get client that doesn't have other implications. That being said this hasn't been a problem for a lot of projects because the solid parts could be built with that setting and then the setting could be absent from the runtime when running. |
I can't import Solid's import html from `solid-js/html` Causes:
Solid's https://github.com/solidjs/solid/blob/main/packages/solid/html/src/index.ts#L17 The solution is Solid should export And if |
Not only does ryansolid/dom-expressions#345 fix this error for Solid Start, but it fixes the error for all SSR frameworks. For example, I've had this error turning up for me and other people where were trying to use Lume in Svelte Kit, Next, etc. Gonna be really nice to have this one finally fixed! |
Aha! Well I've verified and tested that this is fixed in the above PR ^, as far as import But now that that's out of the way, I've discovered more similar issues in separate packages that I'll also fix:
Error with SSR enabled, no error with SSR disabled. I'll update this PR to also include updates for other sub-folders such as |
I've updated #2269 and can confirm that the updated build of solid-js in a Solid Start app prevents any SSR errors due to I am still having a hydration error of some kind, but |
Yeah merged into |
Describe the bug
When I import
solid-js/html
as an ES module from Node.js, I get the following error:Your Example Website or App
n/a
Steps to Reproduce the Bug or Issue
For example, in the Node.js REPL:
Expected behavior
I expect the
import
to succeed and not throw an error.Screenshots or Videos
No response
Platform
Additional context
I'm looking to write some custom tooling for writing automated tests from Node.js and was surprised to see this error.
After some searching, I found this issue: #1483, which clued me into the fact that there are separate builds for the browser and for Node.js.
It looks like because the
html
tag function returns a DOMNode
,solid-js/html
is a browser-only package. I am, however, able to proceed if I configure Node.js to prefer browser packages:Because
solid-js/html
importssolid-js/web
, there's no way to specify that the browser packages should be used without passing in arguments to Node.js. To make this easier, couldsolid-js/html
directly import the browser build ofsolid-js/web
instead? There are probably trade-offs to doing that, but I'm hoping to have easy ways to run Solid from a Node.js + JSDOM environment.The text was updated successfully, but these errors were encountered: