gajus / lightship

Abstracts readiness, liveness and startup checks and graceful shutdown of Node.js services running in Kubernetes.
Other
515 stars 33 forks source link

CommonJS issue #69

Open pauliusg opened 5 months ago

pauliusg commented 5 months ago

As I understand lightship library is distributed as es and commonjs module: However it has dependency serialize-error ^11.0.0 which from v9 has breaking change and is pure es module: https://github.com/sindresorhus/serialize-error/releases/tag/v9.0.0

So looks like now lightship does not support commonjs?

UPDATE: In my project I get error:

Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules\lightship\dist\cjs\index.js from ...\SignalingAdapter.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in ...\node_modules\lightship\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

I can run newest version of lightship only with some hacks. In my project package.json I added (then npm overrides version of lib):

  "overrides": {
    "serialize-error": "^8.1.0"
  }

Additionally I had to make manual edit in installed lightship ...\node_modules\lightship\package.json to remove line:

  "type": "module",

But this workaround is not acceptable in prod environment :)

UPDATE2: seems that my issue is duplicate of https://github.com/gajus/lightship/issues/67 But I think I have provided valuable information where the root cause is.

mstroiu commented 5 months ago

Same issue here! 🙃

dariusdev commented 3 months ago

Same here. Currently is not possible to use it with typescript or nestjs

djnym commented 2 weeks ago

I see something was attempted last year to fix this, but as this is still happening any idea when it might be addressed? Is this project still active?