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

CJS import issue with middy v4 when using node16/nodenext #1242

Open
acommodari opened this issue Sep 27, 2024 · 5 comments
Open

CJS import issue with middy v4 when using node16/nodenext #1242

acommodari opened this issue Sep 27, 2024 · 5 comments
Labels

Comments

@acommodari
Copy link

acommodari commented Sep 27, 2024

Describe the bug
A clear and concise description of what the bug is.

We are using middy in a common js project so we tried installing @middy/core v4 but we are getting errors because it seems your types are incorrect.

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("@middy/core")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts' or create a local package.json file with `{ "type": "module" }`.ts(1479)

Checking on Are The Types Wrong? also confirms this.

It would be great if you could backport a fix to v4 so those of us using commonjs could still use this library without having to give up on module node16/nodenext

To Reproduce
How to reproduce the behaviour:

  1. Create a new common js project with typescript and make sure the tsconfig.json uses module: node16 or nodenext as well as esModuleInterop: true
  2. import middy using import middy from '@middy/core

Expected behaviour
As mentioned above it would be great if we could have a patch to v4 with fixed types

Environment (please complete the following information):

  • Node.js: 20
  • Middy: 4.7.0
  • AWS SDK 3.x.x

Additional context
Add any other context about the problem here.

@acommodari acommodari added the bug label Sep 27, 2024
@kapitanluffy
Copy link

Have you tried downgrading to a lower version? I have 4.6 and it also occurs to me. I initially thought that v4 would still support cjs (albeit deprecated) but apparently this seems not to be the case

@acommodari
Copy link
Author

acommodari commented Oct 10, 2024

Have you tried downgrading to a lower version? I have 4.6 and it also occurs to me. I initially thought that v4 would still support cjs (albeit deprecated) but apparently this seems not to be the case

if you use https://arethetypeswrong.github.io/ you'll see the v4 and v3 both have this issue the only one that will work is v2 but event that version has its own issues so this has been an ongoing issue since basically the beginning

only v5 works properly but is only esm so doesnt work for us until we get require(esm) but thats still at least a few months away

@kapitanluffy
Copy link

kapitanluffy commented Oct 10, 2024

Have you tried downgrading to a lower version? I have 4.6 and it also occurs to me. I initially thought that v4 would still support cjs (albeit deprecated) but apparently this seems not to be the case

if you use https://arethetypeswrong.github.io/ you'll see the v4 and v3 both have this issue the only one that will work is v2 but event that version has its own issues so this has been an ongoing issue since basically the beginning

only v5 works probably but is only esm so doesnt work for us until we get require(esm) but thats still at least a few months away

I think you can actually do that now? Thats is what I did. Try it and let me know of it works on your end.

@willfarrell
Copy link
Member

There is a new flag --experimental-require-module that can be used. v6.0.0 already has support added in for it. I've just been busy and haven't released the alpha yet.

@kapitanluffy
Copy link

@willfarrell oh there's a flag? I am pretty sure I did not enable any flags on my end. weird..

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

No branches or pull requests

3 participants