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

Module "mysql2" has no exported member "Types" #1938

Closed
neeppy opened this issue Apr 7, 2023 · 2 comments
Closed

Module "mysql2" has no exported member "Types" #1938

neeppy opened this issue Apr 7, 2023 · 2 comments

Comments

@neeppy
Copy link

neeppy commented Apr 7, 2023

Hello,

Apparently, when using typescript, the Types export from index.js is not being resolved. I assume this is because it's missing from the index.d.ts file.

image

However, logging out Types works as expected, even if it says that it's missing, so a simple @ts-ignore works as a workaround. Trying to import from the promise API, however, doesn't work, as expected, since the Types object is not exported.

Is there a reason why the column types couldn't be exported from mysql2/promise as well?

Thanks a lot!

@wellwelwel
Copy link
Sponsor Collaborator

wellwelwel commented Jun 24, 2023

Hi @cptpaws, can you check it in version ^3.4.1?


Is there a reason why the column types couldn't be exported from mysql2/promise as well?

Now, you can import it from both mysql2 and mysql2/promise 🤹🏻‍♀️


Just a suggestion in case you use it with ES Module

To import the Constants, I recommend you do it as follows:

import mysql from 'mysql2';
// or
import * as mysql from 'mysql2';

// then
mysql.Types;

When using by this way in an ES Module

import { Types } from 'mysql2';

It will print an error like:

import { Types } from 'mysql2';
         ^^^^^
SyntaxError: Named export 'Types' not found. The requested module 'mysql2' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'mysql2';
const { Types } = pkg;

As before, it's just a suggestion 🙋🏻‍♂️

@wellwelwel
Copy link
Sponsor Collaborator

After version ^3.4.1, you can use the Types constants.

Some examples:


I'm closing this Issue, but feel free to ask anything 🙋🏻‍♂️

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