Node-mysql2: I can not import * as mysql from 'mysql2' in typescript

Created on 28 Jul 2017  Â·  12Comments  Â·  Source: sidorares/node-mysql2

Hi node-mysql2 team,

Could you please add the declaration file for module 'node-mysql2'? Currently, I can not find the declaration. so I have to use the "require" to load 'node-mysql2'. Howerver, the project tslint rule ask us for "import * as mysql from 'mysql2'".

Since node-mysql2 is so popular, I hope, node-mysql2 will support typescript for type checking in the future.

Thanks a lot.
Mike

Most helpful comment

I think he refers to the fact that now either you publish @types/mysql2 to the Types repo or the mantainers of the repo should add a .d.ts file with the defined types in the root folder of the project.
Is that something that you could do?

All 12 comments

there are typings available at https://github.com/types/npm-mysql2 , see https://github.com/sidorares/node-mysql2/issues/482#issuecomment-286221116

is that enough to fix your issue?

Hi @sidorares, thank you so much!
if I can use "npm install --save-dev types/mysql2" or "npm install -g types/mysql2", that will be perfect.
Yesterday, I tried to use "npm install --save-dev types/mysql2", the result is ,

404 Registry returned 404 for GET on https://registry.npmjs.org/@types%2fmysql2
404  '@types/mysql2' is not in the npm registry.

ping @felixfbecker

@mamingzhi does work for you: https://github.com/typings/registry/issues/778#issuecomment-286220701?

@sidorares
I am using typescript 2.3.4 and the new way is "npm install types/xxxx".
I tried the

npm install --save-dev types/mysql2#semver:1.3.5
npm ERR! git clone --template=C:\temp\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-
5-7a65a6a8: Cloning into bare repository 'C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-5-7a65a6a8'...
npm ERR! git clone --template=C:\temp\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-
5-7a65a6a8: ssh: connect to host github.com port 22: Connection timed out
npm ERR! git clone --template=C:\temp\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-
5-7a65a6a8: fatal: Could not read from remote repository.
npm ERR! git clone --template=C:\temp\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-
5-7a65a6a8:
npm ERR! git clone --template=C:\temp\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-
5-7a65a6a8: Please make sure you have the correct access rights
npm ERR! git clone --template=C:\temp\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\temp\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-3-
5-7a65a6a8: and the repository exists.

my typescript version does not support the typingscommand.
I can not run typings install --save mysql2

Sorry, the new way should be "npm install --save-dev @types/mysql2", however I can still not get he msql2 declaration files.

sorry, I have very little practical experience with typescript and related tools. If you need any change from library side to make it easier to integrate let me know (but please explain what change required)

@mamingzhi I cannot reproduce your error, I have no problem installing the typings.

with npm 5 (supports semver: syntax)

✔ ~/test
09:13 $ npm i --save-dev types/mysql2#semver:^1.0.0

+ @types/[email protected]
updated 1 package and moved 1 package in 0.831s

with npm 4

✔ ~/test
09:15 $ npm i --save-dev types/mysql2#v1.0.0
/Users/felix/test
└─┬ @types/[email protected]  (git://github.com/types/mysql2.git#eec1760a55ec3236a60675f74b177587df71068f)
  └── @types/[email protected]  (git://github.com/types/mysql.git#da645a82afd66419ed439dddf174648aa68ba1f9)

The errors you posted indicate that you tried to install @types/mysql2 from the registry, not types/mysql2 from GitHub.

Not sure what you are referring to with "the new way".

I think he refers to the fact that now either you publish @types/mysql2 to the Types repo or the mantainers of the repo should add a .d.ts file with the defined types in the root folder of the project.
Is that something that you could do?

...or you install typings from the @types or from GitHub. Contributing to DT is cumbersome. Waiting for Microsoft/types-publisher#4

Hi @felixfbecker,

Thank you for your reply,

This moring, I tried it again,
Are there some net issues for accessing the git? I am not sure.

C:\typescript-rest-boilerplate>npm install --save-dev mysql2
[email protected] C:\typescript-rest-boilerplate
`-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  |   `-- [email protected]
  +-- [email protected]
  +-- [email protected]
  +-- [email protected]
  +-- [email protected]
  +-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  | +-- [email protected]
  | `-- [email protected]
  +-- [email protected]
  `-- [email protected]

C:\typescript-rest-boilerplate>npm i --save-dev types/mysql2#semver:^1.0.0
npm ERR! git clone --template=C:\Users\Mike\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\Users\Mike\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-0-0-7a65a6a8: undefined
npm ERR! git clone --template=C:\Users\Mike\AppData\Roaming\npm-cache\_git-remotes\_templates --mirror [email protected]:types/mysql2.git C:\Users\Mike\AppData\Roaming\npm-cache\_git-remotes\git-github-com-types-mysql2-git-semver-1-0-0-7a65a6a8: undefined
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "--save-dev" "types/mysql2#semver:1.0.0"npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! code ENOGIT

npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\typescript-rest-boilerplate\npm-debug.log

The new way I mentioned is,

I tried the "npm install --save-dev @types/mysql2" (the firt time I want to install mysql2 definitions, but it fail )

I also tried the "npm install --save-dev types/mysql2" (without @) and it does still not work.

https://stackoverflow.com/questions/39261204/typings-vs-types-npm-scope
https://blogs.msdn.microsoft.com/typescript/2016/06/15/the-future-of-declaration-files/

Sorry, I think I get the root cause "there is an issue for my git."

but I hope I can use "npm install -D @types/xxxx" command.

thanks a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gajus picture gajus  Â·  3Comments

c24w picture c24w  Â·  5Comments

juliandavidmr picture juliandavidmr  Â·  4Comments

hellopat picture hellopat  Â·  6Comments

HulioEglesias picture HulioEglesias  Â·  4Comments