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

Error when using solid.js packages: web.template is not a function #4652

Closed
1 task
amirhhashemi opened this issue Sep 7, 2022 · 14 comments · Fixed by #5233
Closed
1 task

Error when using solid.js packages: web.template is not a function #4652

amirhhashemi opened this issue Sep 7, 2022 · 14 comments · Fixed by #5233
Assignees
Labels
- P2: nice to have Not breaking anything but nice to have (priority) ecosystem: external External library doesn't work

Comments

@amirhhashemi
Copy link
Contributor

amirhhashemi commented Sep 7, 2022

What version of astro are you using?

1.2.1

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn classic

What operating system are you using?

Linux

Describe the Bug

When I want to use Solid.js packages that are using @solid-primitives/props package internally, like @solid-aira/focus and @motionone/solid, I get this error:

 error   web.template is not a function
  Code:
    > 46 | const _tmpl$ = /*#__PURE__*/web.template(`<label><input type="checkbox"> <span></span> </label>`, 5),
         |                                 ^
      47 |       _tmpl$2 = /*#__PURE__*/web.template(`<label><span></span> <input type="number"> </label>`, 5),
      48 |       _tmpl$3 = /*#__PURE__*/web.template(`<label><span></span> <input type="text"> </label>`, 5),
      49 |       _tmpl$4 = /*#__PURE__*/web.template(`<label><span></span> <select></select> </label>`, 6),

It works fine when I use @solid-primitives/props directly. The error only happens when it's a transitive dependency. Also adding the package to vite.ssr.noExternal doesn't help.

Link to Minimal Reproducible Example

Here is an example with @motionone/solid

https://stackblitz.com/edit/github-lepeza

Participation

  • I am willing to submit a pull request for this issue.
@matthewp
Copy link
Contributor

matthewp commented Sep 7, 2022

You likely need to use noExternal config because the package is not ESM.

@amirhhashemi

This comment was marked as outdated.

@amirhhashemi

This comment was marked as outdated.

@amirhhashemi
Copy link
Contributor Author

amirhhashemi commented Sep 7, 2022

@matthewp When I use @solid-primitives/props package directly, it works fine. But when another package (like @solid-aria) uses that internally, I get that error. I still can't tell the cause of the error as I know nothing about this stuff but it should be investigated.

@thetarnav
Copy link

thetarnav commented Sep 7, 2022

Another example with @motionone/solid that also ships preserved jsx, and has a dependency to @solid-primitives/props
https://stackblitz.com/edit/github-7cxbsf-py2rr6

@matthewp matthewp added the ecosystem: external External library doesn't work label Sep 22, 2022
@matthewp matthewp added the - P2: nice to have Not breaking anything but nice to have (priority) label Oct 6, 2022
@matthewp matthewp self-assigned this Oct 7, 2022
@bluwy
Copy link
Member

bluwy commented Oct 13, 2022

Looks like #5059 didn't fully fix that, we may need to recursively noExternal solidjs deps to fix this. A workaround is to add ['@motionone/solid', '@solid-primitives/props'] to vite.ssr.noExternal.

But even with that configuration, I'm getting:

Error: Unable to render Motion because it is undefined!
Did you forget to import the component or is it possible there is a typo?
    at Module.renderComponent (/node_modules/astro/dist/runtime/server/render/component.js:76:11)

which may be another issue.

@matthewp matthewp assigned bluwy and unassigned matthewp Oct 21, 2022
@bluwy
Copy link
Member

bluwy commented Oct 24, 2022

Actually it seems like that error doesn't happen anymore, might be a fluke. I'll be automating the workaround for this PR by updating vite-plugin-solid to do that, and have @astrojs/solid-js to use vite-plugin-solid.

@amirhhashemi
Copy link
Contributor Author

Actually it seems like that error doesn't happen anymore, might be a fluke. I'll be automating the workaround for this PR by updating vite-plugin-solid to do that, and have @astrojs/solid-js to use vite-plugin-solid.

That's awesome. Thank you for taking the time to fix this. I'm gonna close this issue. Feel free to re-open it if you think it's not fully fixed. Unfortunately, I'm super busy and can't test it out. Maybe @thetarnav can test it. Thank you again.

@thetarnav
Copy link

The solid-primitives/props has been changed in the last version to not ship JSX.
motionone/solid still is though
Not sure if that's correlated, but it might be

@bluwy
Copy link
Member

bluwy commented Oct 24, 2022

Yeah I'll still need to automate the noExternal part. Re-opening for now.

@bluwy
Copy link
Member

bluwy commented Oct 27, 2022

I was able to replicate the Unable to render Motion because it is undefined! error again and it seems to be because Motion.* is a proxy component that's interfering with Astro's component rendering process. This one might be tricky to untangle.

@adharshmk96
Copy link

I have the same issue when testing a function for solid.

  ● Test suite failed to run

    TypeError: (0 , _web.template) is not a function

      1 | import { render, screen } from '@solidjs/testing-library';
      2 | import userEvent from '@testing-library/user-event';
    > 3 | import createForm from '../index';
        |                                   ^
      4 |
      5 | function DummyComponent(register, onSubmit) {
      6 |   return function component() {

here's the repo https://github.com/adharshmk96/solid-hook-form

@wakaztahir
Copy link

This error occurs, Please re open this issue, as I am getting this error with a package I published on github which contains solid jsx

@wakaztahir
Copy link

wakaztahir commented Oct 1, 2023

@matthewp Here's a reproducer

https://github.com/Qinetik/anique-template/tree/fe21a721411a78a36244d6293cf04bd9e4b4f490

This also happens with solid-start when ssr : true since My library uses template function which is present inside SolidJS web client package rather than the server package, since there's no template function in server package, It produces an error

UPDATE

has been fixed, It was an issue with the library, I am using tsup now which fixes this issue ! tsup packages the library real nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) ecosystem: external External library doesn't work
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants