minio-js
minio-js copied to clipboard
NodeJS 13 ECMAScript Modules | Babel Error
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 (https://github.com/facebook/jest/issues/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
Hey @kaankabalak @kannappanr any news about this issue ?
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.
this is already fixed, will be released in >7.1.0
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'
How are you importing @BjoernRave ?
I am running
7.1.3and still experience the error when trying to run a typescript file withtsx. 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'
@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 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