Skip to content

[@lit-labs/nextjs] TypeError: this._$Ek is not a function #3845

Open

Description

@raoufswe

Which package(s) are affected?

SSR (@lit-labs/ssr)

Description

When @lit-labs/nextjs is added to a next@13 app that imports a lit component package in a yarn workspace monorepo, the server throws the following error.

Screenshot 2023-04-26 at 17 45 48

I suspect the issue might originate from a conflict of sub-dependencies as the app workspace sets hoistingLimits to workspaces to hoist dependencies to the top level within the scope of the workspace. removing this config solves the issues but it isn't favorable in our case to avoid version conflicts between different packages in the monorepo.

extra details that might be useful for debugging:

  • the imported lit component is a button, and the bug persists with and without wrapping it with the React wrapper
  • the lit component is tested in different client-side environments such as react, vue and anuglar and it works as expected, so I assume it's an SSR-related issue.

Reproduction

  • the bug can be reproduced in this branch
  • the readme has some instructions to set up the repo but running yarn in the root and then cd-ing to app/examples/wc-next13 and running yarn dev should be enough to reproduce the issue.

Workaround

removing installConfig here or just moving @lit-labs/nextjs to the root package.json should get rid of the error.

Alternatively, defining the button component directly in the src directory of the next app solves the issue as well.

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

0.1.1

Browser/OS/Node environment

Chrome
next@13

Activity

  1. raoufswe commented on Apr 26, 2023

    @raoufswe
    ContributorAuthor

    I'm a bit new to the codebase and still trying to figure my way out, but I believe the issue is somewhere in these few lines as commenting them seems to get rid of the error, but I don't think the deep SSR of the component works as only the custom tag element is served.

    Update #2

    The issue happens when the react ssr package is used and imported directly to the next app, so I believe it isn't originated from the next plugin side effect logic.

    Update #3

    I've updated the default node export file manually to point to the development version and that seems to get rid of the error. I had to update a bunch of packages as well in case that helps :DDD

        "node": {
            "development": "./node/development/reactive-element.js",
            "default": "./node/development/reactive-element.js"
          }
    
  2. self-assigned this
    on Apr 27, 2023
  3. moved this to 📋 Triaged in Lit Project Boardon Apr 27, 2023
  4. augustjk commented on Apr 28, 2023

    @augustjk
    Member

    @raoufswe Regarding update 3, the problem with doing that would be that you won't get the production version when you need it. I'm curious if yarn build && yarn start will work with that.

    It does confirm that the problem is something is pulling the production (default) build when it's running in dev mode with yarn dev.

  5. raoufswe commented on Apr 28, 2023

    @raoufswe
    ContributorAuthor

    @augustjk yea that's definitely not ideal, it's just a finding that I came across and thought might help us find the actual problem :'(

    Update # 1 -> yarn build && yarn start works as expected 💯

  6. augustjk commented on May 4, 2023

    @augustjk
    Member

    I'm seeing this in a different project with npm. I'll have to investigate further. Something about the next cli running in dev mode is not bringing in the correct export from @lit/reactive-element depending on where it's being imported from.

    I have found that running NODE_OPTIONS=--conditions=development npm run dev is a valid workaround for me. @raoufswe maybe NODE_OPTIONS=--conditions=development yarn dev might work for you?

    Needs further investigation for this to work without this.

  7. hrmcdonald commented on May 10, 2023

    @hrmcdonald

    We've run into what appears to be a similar issue here with astro, vite, and pnpm.

    Lit is in dev mode. Not recommended for production! See https://lit.dev/msg/dev-mode for more information.
    Multiple versions of Lit loaded. Loading multiple versions is not recommended. See https://lit.dev/msg/multiple-versions for more information.
     error   r._$AT is not a function
      File:
        /<my-repo-path>/apps/docs/<my-repo-path>/node_modules/.pnpm/[email protected]/node_modules/lit-html/node/lit-html.js:6:3039
      Stacktrace:
    TypeError: r._$AT is not a function
        at N (file:///<my-repo-path>/node_modules/.pnpm/[email protected]/node_modules/lit-html/node/lit-html.js:6:3039)
        at renderValue (file:///<my-repo-path>/node_modules/.pnpm/@[email protected]/node_modules/@lit-labs/ssr/lib/render-value.js:341:17)
        at renderValue.next (<anonymous>)
        at renderTemplateResult (file:///<my-repo-path>/node_modules/.pnpm/@[email protected]/node_modules/@lit-labs/ssr/lib/render-value.js:391:24)
        at renderTemplateResult.next (<anonymous>)
        at renderValue (file:///<my-repo-path>/node_modules/.pnpm/@[email protected]/node_modules/@lit-labs/ssr/lib/render-value.js:345:16)
        at renderValue.next (<anonymous>)
        at LitElementRenderer.renderShadow (file:///<my-repo-path>/node_modules/.pnpm/@[email protected]/node_modules/@lit-labs/ssr/lib/lit-element-renderer.js:69:16)
        at renderShadow.next (<anonymous>)
        at render (@astrojs/lit/server.js:79:3)
        at render.next (<anonymous>)
        at Object.renderToStaticMarkup (@astrojs/lit/server.js:108:11)
        at renderFrameworkComponent (/<my-repo-path>/node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected]/node_modules/astro/dist/runtime/server/render/component.js:178:66)
    

    The NODE_OPTIONS=--conditions=development workaround fixes this issue for us for now.

  8. steveworkman commented on Oct 3, 2023

    @steveworkman
    Contributor

    I've found this issue recently when using file paths to import a package rather than getting a bundled version of the component from the package registry. The error doesn't happen when using a production build

  9. raoufswe commented on Oct 11, 2023

    @raoufswe
    ContributorAuthor

    I did a bit more digging into this and found out that when a nextjs app is not hosted in a monorepo, the dev server won't throw even if you don't add the --conditions=development flag. However, as shown in my recording, the app is referencing production builds unless you explicitly add the flag to next dev👀

    screen-recording-2023-10-11-at-103005_45qeUVbe.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions