Skip to content

NodeJS 13 ECMAScript Modules | Babel Error #835

@roonie007

Description

@roonie007

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions