Skip to content

Conversation

AlessioGr
Copy link
Contributor

@AlessioGr AlessioGr commented Mar 2, 2025

Updating to 0.26.0 causes our project to crash executing a standalone node script that imports from lexical (this cannot be reproduced when importing lexical from a bundler).

The reason for that is this import that made it into the lexical build:

CleanShot 2025-03-01 at 21 30 26@2x

This is caused by the following newly introduced import statement in packages/lexical/src/LexicalNode.ts:

import {Klass, KlassConstructor, NODE_STATE_KEY} from 'lexical';

Imports from self like that are not valid and cause issues. I have verified that removing it fixes our issue.

Notably, such self-import statements can easily slip in (especially with VS Code’s auto-import suggestions). To help guard against this, we’ve created a custom ESLint rule (no-imports-from-self) that warns developers if they accidentally import from the same package. I think it would be a good idea to introduce something like that in this monorepo - feel free to copy this rule or use our @payloadcms/eslint-plugin package if interested.

To Reproduce

  1. Create a script.js:
import { TabNode } from 'lexical'
console.log(TabNode)
  1. Run it using node src/script.js
  2. The following error will be thrown:
Warning: Detected unsettled top-level await at
file:///Users/alessio/Documents/GitHub/payload20/node_modules/.pnpm/[email protected]/node_modules/lexical/Lexical.node.mjs:9
const mod = await (process.env.NODE_ENV !== 'production' ? import('./Lexical.dev.mjs') : import('./Lexical.prod.mjs'));

Copy link

vercel bot commented Mar 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2025 4:33am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2025 4:33am

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 2, 2025
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you would run into problems with this unless you were not using the build artifacts from lexical? Avoiding this problem in the future is only feasible if you can also provide a unit test of some kind that can detect it.

@etrepum
Copy link
Collaborator

etrepum commented Mar 2, 2025

Never mind, I can see how this causes node problems now. Please go ahead and submit a PR that adds the appropriate lint rules or tests to ensure this doesn’t reoccur.

@AlessioGr
Copy link
Contributor Author

AlessioGr commented Mar 2, 2025

Will do, thank you for the speedy reply! And yea, adding a unit test for this will be tricky, as this only happens when importing from the built, installed version of lexical.

A unit test would need to:

  1. Build the lexical package
  2. Run npm pack
  3. Move the tgz file into some test directory
  4. modify the package.json to reference the tgz
  5. Run npm install
  6. Then it can execute the script

Given that this should happen in any node script that imports lexical outside a bundler, would it be possible to get an early 0.26.1 release?

@etrepum
Copy link
Collaborator

etrepum commented Mar 2, 2025

We already have some tests that do that sort of thing (e.g. the integration tests), so it’s not something too crazy.

Yes, there will be a patch release next week.

@etrepum etrepum added this pull request to the merge queue Mar 2, 2025
Merged via the queue into facebook:main with commit 4ca9a92 Mar 2, 2025
40 checks passed
This was referenced Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants