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

Does not generate valid cjs #67

Open fooku18 opened 10 months ago

fooku18 commented 10 months ago

The current version does not generate a valid CommonJS distribution. This is because the tsconfig file for the cjs does not override the defaults for the module value:

// tsconfig.build-cjs.json
{
  "compilerOptions": {
    "noEmit": false,
    "outDir": "dist/cjs"
  },
  "extends": "./tsconfig.json",
  "include": [
    "src"
  ]
}

this can be fixed by setting compilerOptions.module to CommonJS

ktalebian commented 10 months ago

Same here

fooku18 commented 10 months ago

This will actually not work entirely. The reason is that when setting type: "module", also the generated CJS files need to have the .cjs extension instead of .js as it will generate as of now. Even if the file extension is adjusted, the dependency to serialize-error (which is a pure ESM module only), will prevent this from working. I guess with the dependency to serialize-error, generating a CJS distribution is pointless in the first place.

devthejo commented 10 months ago

using version 9.0.3 of lightship I get this error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /my-project/node_modules/lightship/dist/cjs/index.js from /my-project/plugins/lightship/index.js not supported. /my-project/node_modules/lightship/dist/cjs/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 rename /my-project/node_modules/lightship/dist/cjs/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 /my-project/node_modules/lightship/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

d33vil commented 6 months ago

Same Here

S-K-Lieren commented 5 months ago

Our company is also affected by this and we'd highly appreciate seeing this fixed as soon as possible. Thanks in advance :)