payload generate:importmap
Fails with Custom Lexical Editor Feature
#10011
-
Describe the BugI've implemented a custom feature for the Lexical editor that allows marking text with colors(just add a tailwind class). This feature is heavily inspired by the While the feature is nearly complete, I encounter an error when running the command
My Own ObservationsThrough testing, I narrowed the issue to the
If I remove the If I remove the nodes array, run Since it works using the above method, I can't figure out why this is happening, Link to the code that reproduces this issuehttps://github.com/Tanish2002/custom-color-feature-repro Reproduction StepsError Scenario
git clone <repository-link>
cd custom-color-feature-repro
pnpm install
pnpm payload generate:importmap 4.Observe the error output, which matches the following: TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".css" ... WorkaroundTo bypass the issue and proceed with development:
git clone https://github.com/Tanish2002/custom-color-feature-repro
cd custom-color-feature-repro
pnpm install
return {
...
nodes: [
createNode({ ... }),
createNode({ ... }),
],
...
} To: return {
...
// nodes array removed
}
pnpm payload generate:importmap
pnpm run dev
If you re-run the Which area(s) are affected? (Select all that apply)plugin: other, plugin: richtext-lexical Environment Info
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 6 replies
-
That error usually implies there is something wrong with your path (in this case, ClientFeature in createServerFeature). However I've only seen it in collection level imports, not custom lexical features so I could be wrong. One thing I can see is that your client feature is using an index.tsx, whereas the example is using index.ts. Could be nothing but worth a shot. |
Beta Was this translation helpful? Give feedback.
-
I've tried all types of path formats, converting the import to a default import using
Tried that, didn't work as well, the only reason I'm using |
Beta Was this translation helpful? Give feedback.
-
@rilrom One more thing, I don't think this is even caused by the If I remove the So I believe the issue lies somewhere in |
Beta Was this translation helpful? Give feedback.
-
So it looks to be specific to how you have implemented your custom nodes. If I replace your custom node with the below:
Then I recommend slowly working your way through one of your custom nodes until you find the cause. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @rilrom! I’ve identified the source of the bug in the
The issue seems to be with the As a workaround, I’ve written a custom helper function to specifically check for span elements, which resolves the issue for now:
Would appreciate any insights into why |
Beta Was this translation helpful? Give feedback.
-
Glad you've found a workaround! Could you try importing it from '@payloadcms/richtext-lexical/lexical/utils' instead? It seems the isHTMLElement that you are referencing is different to the one used in the link feature. |
Beta Was this translation helpful? Give feedback.
-
Yeah I just realized that as well, but that still doesn't explain the issue with importMap command |
Beta Was this translation helpful? Give feedback.
-
Hey @Tanish2002 I can shine some light on this. You are importing a CSS file in server-only code, which is crashing the This is why all of our CSS for Lexical features is abstracted out of the server-side files and is present only in the files meant to be consumed solely in a browser context. Browser code goes through Turbopack / Webpack, but the config itself (and the server-side part of Lexical components) is Node-only, so there, CSS will break the process. If you have a barrel file, or a single file that imports / exports many things (including a CSS file), this would crash the Node scripts that Payload uses. The Does that make sense? I'll convert this to a discussion because I think that it will be beneficial for others. Happy to continue to help as well. |
Beta Was this translation helpful? Give feedback.
-
@jmikrut That makes a lot more sense now! Thanks. I do think the docs should mention that Nodes shouldn't contain any client side code. Also |
Beta Was this translation helpful? Give feedback.
-
I'm getting this same error when using |
Beta Was this translation helpful? Give feedback.
Hey @Tanish2002 I can shine some light on this. You are importing a CSS file in server-only code, which is crashing the
generate:importmap
command (because that is a Node command and doesn't know how to parse CSS).This is why all of our CSS for Lexical features is abstracted out of the server-side files and is present only in the files meant to be consumed solely in a browser context. Browser code goes through Turbopack / Webpack, but the config itself (and the server-side part of Lexical components) is Node-only, so there, CSS will break the process.
If you have a barrel file, or a single file that imports / exports many things (including a CSS file), this would crash the Node scripts t…