lightship icon indicating copy to clipboard operation
lightship copied to clipboard

Does not generate valid cjs

Open fooku18 opened this issue 1 year ago • 5 comments

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

fooku18 avatar Aug 17 '23 15:08 fooku18

Same here

ktalebian avatar Aug 18 '23 00:08 ktalebian

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.

fooku18 avatar Aug 18 '23 06:08 fooku18

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).

devthejo avatar Sep 08 '23 08:09 devthejo

Same Here

d33vil avatar Jan 04 '24 18:01 d33vil

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

S-K-Lieren avatar Feb 08 '24 07:02 S-K-Lieren