Background
I've got an NX workspace with a react front-end and an express back-end. I want to add some dependencies to the back-end application but am having trouble adding dependencies that are ESM Libs.
When running nx run express-server:serve which uses the @nx/js:node executor I get the following error
Error [ERR_REQUIRE_ESM]: require() of ES Module Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
Research
I have been reading any related post/thread (see list below) that I can find but I haven't been able to find a solution to this. My understanding is, that this isn't a bug with NX but with the rise of ESM only libs, there must be a workaround for this.
I did make an attempt to update my workspace to ESM but it seems the support for this in NX is lacking and the end result just produced other errors. I would like to continue using NX and be able to support the importing of ESM only libs.
Related Threads
- https://github.com/nrwl/nx/issues/11335
- https://github.com/nrwl/nx/pull/10414
- https://github.com/nrwl/nx/issues/10565
- https://github.com/nrwl/nx/issues/7872
- https://github.com/nrwl/nx/issues/10296
- https://github.com/nrwl/nx/issues/18974
Sample code
npm inx run express-server:build(works)nx run express-server:serve(fails with above error)
This is a simple contrived example to demonstrate the problem. I know I could just downgrade nanoid to version 3 but I have other ESM libs that I can't downgrade.