Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm vs. commonjs #119

Closed
alex-dixon opened this issue Jun 19, 2023 · 6 comments
Closed

esm vs. commonjs #119

alex-dixon opened this issue Jun 19, 2023 · 6 comments

Comments

@alex-dixon
Copy link

alex-dixon commented Jun 19, 2023

Hello! Thank you for this library.

I am receiving the following typescript error on 0.12.1:

TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("effect-http")' call instead.   To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field "type": "module" to 'package.json'.

I was not seeing this error in past versions.

Is the library no longer commonjs compatible?

@sukovanej
Copy link
Owner

Hey, I'm aiming to support both cjs and esm. Unfortunately, I was unable to reproduce the typescript error but I checked there is indeed a problem with the cjs version. Please try with version 0.14.1 and let me know.

@alex-dixon
Copy link
Author

Thank you. Just checked on 0.14.1 and I'm seeing the same thing.

On a local fork if I remove "type": "module" from the effect-http package.json it appears to fix it. Not sure what other havoc that change would make. For whatever it's worth it looks like other effect packages do not set "type": "module".

@sukovanej
Copy link
Owner

sukovanej commented Jun 19, 2023

Alright, I tried that - v0.14.3. Do you have the repo it's not working on available publically, or share a tsconfig.js? I'm trying it on my sample cjs and I don't see the error so it might be a specific configuration in the tsconfig.

@alex-dixon
Copy link
Author

alex-dixon commented Jun 19, 2023

Yes. Apologies. Meant to do that initially. Here it is:

{
  "compilerOptions": {
    "target": "es2022",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "moduleResolution": "Node16",
    "exactOptionalPropertyTypes": true,
    "outDir": "./dist",
    "skipLibCheck": true,
    "plugins": [
      {
        "name": "@effect/language-service"
      }
    ]
  }
}

@alex-dixon
Copy link
Author

Confirmed working on my end on 0.14.3

@sukovanej
Copy link
Owner

Aha! It is an "incorrect" conditional export setting in effect-http for the node16 resolution setting. For whatever reason, typescript demands *.d.cts declaration files for require imports (microsoft/TypeScript#50466) and ignores the specified *.d.ts. The DX of making typescript work is really something... 😢

Anyway, thanks a lot for sharing the issue. I'll discuss the proper package configuration with people on the effect discord. For now, the setup should work for both esm and cjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants