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

NodeJS 13 ECMAScript Modules | Babel Error #835

Open
roonie007 opened this issue Mar 5, 2020 · 8 comments
Open

NodeJS 13 ECMAScript Modules | Babel Error #835

roonie007 opened this issue Mar 5, 2020 · 8 comments
Assignees
Milestone

Comments

@roonie007
Copy link

Hey,

We are using the minio module in our project using NodeJS 13 which now supports natively the Import/Export.

But for our tests and since Jest still does not work properly with NodeJS 13 (jestjs/jest#9430) we are using Babel for your tests .

Everything works perfectly with all other modules like mongoose, fastify, moment, multer etc... .

When we added Minio to our project and added our tests, when we run the project in NodeJS 13 everything works perfectly and here is the code :

import Minio from 'minio';

const minioClient = new Minio.Client({
  endPoint: process.env.S3_HOST,
  port: parseInt(process.env.S3_PORT),
  useSSL: false,
  accessKey: process.env.S3_ACCESS_KEY,
  secretKey: process.env.S3_SECRET_KEY
});

and when we run yarn test we get this error from Babel

Test suite failed to run

    TypeError: Cannot read property 'Client' of undefined
      4 | 
    > 5 | const minioClient = new Minio.Client({
        |                               ^
      6 |   endPoint: process.env.S3_HOST,
      7 |   port: parseInt(process.env.S3_PORT),
      8 |   useSSL: false,

But when we change the import Minio from 'minio'; to import * as Minio from 'minio'; the tests now works perfectly but when we run the server using NodeJS 13 we get this error

11:52:35 AM api.1  |  const minioClient = new Minio.Client({
11:52:35 AM api.1  |                      ^
11:52:35 AM api.1  |  TypeError: Minio.Client is not a constructor
11:52:35 AM api.1  |      at *****************************************************/media.js:5:21
11:52:35 AM api.1  |      at ModuleJob.run (internal/modules/esm/module_job.js:110:37)
11:52:35 AM api.1  |      at async Loader.import (internal/modules/esm/loader.js:167:24)

Can you help please ?
I have been stuck with this from yesterday.
More than 150 tests works with the other modules without any problems, but it the problem occurs only with minio.

Thanks

@roonie007
Copy link
Author

Hey @kaankabalak @kannappanr any news about this issue ?

@harshavardhana
Copy link
Member

Hey @kaankabalak @kannappanr any news about this issue ?

We are busy with other priorities right now @roonie007 feel free to send a PR yourself if you do have time.

@trim21
Copy link
Contributor

trim21 commented May 7, 2023

this is already fixed, will be released in >7.1.0

@BjoernRave
Copy link

I am running 7.1.3 and still experience the error when trying to run a typescript file with tsx. It tells me:

TypeError: Cannot read properties of undefined (reading 'Client')

When trying to run it with bun I get:

Missing 'default' import in module '/Users/bjoernrave/projects/sightseer/node_modules/minio/dist/esm/minio.mjs'

@prakashsvmx
Copy link
Member

How are you importing @BjoernRave ?

@trim21
Copy link
Contributor

trim21 commented Oct 3, 2023

I am running 7.1.3 and still experience the error when trying to run a typescript file with tsx. It tells me:

TypeError: Cannot read properties of undefined (reading 'Client')

When trying to run it with bun I get:

Missing 'default' import in module '/Users/bjoernrave/projects/sightseer/node_modules/minio/dist/esm/minio.mjs'

minio doesn't have default exports, you should use wildcard import

import * as minio from 'minio'

@BjoernRave
Copy link

@trim21 okay, it works like that.

Yes I was importing it like:

import Minio from 'minio'

Would be nice if it would work like that though, as that's how most imports work

@trim21
Copy link
Contributor

trim21 commented Oct 3, 2023

@trim21 okay, it works like that.

Yes I was importing it like:

import Minio from 'minio'

Would be nice if it would work like that though, as that's how most imports work

you can configure your babel to make it intercepting like this, or tsconfig allowSyntheticDefaultImports

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

No branches or pull requests

7 participants