You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[@lit-labs/nextjs] TypeError: this._$Ek is not a function #3845
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.
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.
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 installConfighere 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.
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.
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.
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
@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.
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.
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.
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
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👀
Activity
raoufswe commentedon Apr 26, 2023
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
augustjk commentedon Apr 28, 2023
@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 startwill 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.raoufswe commentedon Apr 28, 2023
@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 startworks as expected 💯augustjk commentedon May 4, 2023
I'm seeing this in a different project with npm. I'll have to investigate further. Something about the
nextcli running in dev mode is not bringing in the correct export from@lit/reactive-elementdepending on where it's being imported from.I have found that running
NODE_OPTIONS=--conditions=development npm run devis a valid workaround for me. @raoufswe maybeNODE_OPTIONS=--conditions=development yarn devmight work for you?Needs further investigation for this to work without this.
hrmcdonald commentedon May 10, 2023
We've run into what appears to be a similar issue here with astro, vite, and pnpm.
The
NODE_OPTIONS=--conditions=developmentworkaround fixes this issue for us for now.steveworkman commentedon Oct 3, 2023
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
raoufswe commentedon Oct 11, 2023
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=developmentflag. However, as shown in my recording, the app is referencing production builds unless you explicitly add the flag tonext dev👀screen-recording-2023-10-11-at-103005_45qeUVbe.mp4
chore: add NODE_OPTIONS to make tests run