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

I can not import * as mysql from 'mysql2' in typescript #619

Closed
mamingzhi opened this issue Jul 28, 2017 · 12 comments
Closed

I can not import * as mysql from 'mysql2' in typescript #619

mamingzhi opened this issue Jul 28, 2017 · 12 comments

Comments

@mamingzhi
Copy link

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

@sidorares
Copy link
Owner

there are typings available at https://github.com/types/npm-mysql2 , see #482 (comment)

is that enough to fix your issue?

@mamingzhi
Copy link
Author

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.

@sidorares
Copy link
Owner

ping @felixfbecker

@sidorares
Copy link
Owner

@mamingzhi does work for you: typings/registry#778 (comment)?

@mamingzhi
Copy link
Author

@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 typings command.
I can not run typings install --save mysql2

@mamingzhi
Copy link
Author

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

@sidorares
Copy link
Owner

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)

@felixfbecker
Copy link

felixfbecker commented Jul 28, 2017

@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:https://github.com/types/mysql2.git#eec1760a55ec3236a60675f74b177587df71068f)
  └── @types/[email protected]  (git:https://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".

@kikar
Copy link

kikar commented Jul 28, 2017

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?

@felixfbecker
Copy link

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

@mamingzhi
Copy link
Author

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 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/

@mamingzhi
Copy link
Author

mamingzhi commented Jul 29, 2017

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.

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

4 participants