Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Webpack compiles ElementNode in a class instead of function, generating error

default discord avatar
feyd.harkonnenlast year

I have a strange situation with a custom ElementNode. Building the project locally works fine (Windows 10), but building the project in Github Action with the same Node.js version (but Ubuntu) seems to create a strange situation.



Basically, I have debugged the source of the error, and is a custom ElementNode for Lexical.



If necessary, this is the source code for it:



The compiled code looks the same for both GitHub Action and local.



The only difference that breaks the code and generates an error is the ElementNode. On Github Action (Ubuntu) the ElementNode is compiled as a class:



But on Windows 10 (local) is compiled as a function:



Therefore when the custom node tries to

super()

it will call

d = e.call(this, u) || this;

. This throws the following error:



TypeError: Class constructor re cannot be invoked without 'new'


1. Is an issue related to Payload, Webpack or Lexical?


2. How I can fix it?



Webpack compiles ElementNode in a class instead of function, generating error



Reproduced on Kali Linux

Seems like Webpack doesn't pack well external packages with project itself



Seems like Lexical is already compiled to

ES2019

and Webpack doesn't touch it. Very curios how it works locally.



It may be related to lexical entrypoint:

'use strict'
const Lexical = process.env.NODE_ENV === 'development' ? require('./Lexical.dev.js') : require('./Lexical.prod.js')
module.exports = Lexical;


Yes, disabling Webpack optimization seems to use

Lexical.prod.js

and Webpack doesn't

TOUCH

it. Even using

target: ['web', 'es5']

won't compile Lexical to ES5



Aliasing the

lexical

to the

Lexical.dev.js

doesn't fix the issue. Webpack generates ES5 for the rest of the project, but maintain ES2019 for Lexical.



It may be related to SWC.



Fixed, it's related to SWC because it's excluding node_modules files that are not

ts(x)

. Seems like this is happening under certain conditions and it seems like a bug.

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.