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

vscode development - how to import a new npm module into vscode #34346

Closed
cwtuan opened this issue Sep 14, 2017 · 3 comments
Closed

vscode development - how to import a new npm module into vscode #34346

cwtuan opened this issue Sep 14, 2017 · 3 comments
Assignees
Labels
engineering VS Code - Build / issue tracking / etc. javascript JavaScript support issues

Comments

@cwtuan
Copy link

cwtuan commented Sep 14, 2017

I'm developing a new feature to vscode itself. I want to use a npm module(axios) in the source.

In the root of project,

npm install --save axios

Any in any typescript file of vscode,

import * as axios from 'axios';

There's error: [ts] Cannot find module 'axios'.

But when I import other npm which is already in original vscode package.json such as winreg. Then, the statementimport * as winreg from 'winreg'; doesn't show any error.

Question: How do I import a new npm module into vscode?

@mjbvz
Copy link
Collaborator

mjbvz commented Sep 14, 2017

This seems like a bug when using "moduleResolution": "classic" as we do in VSCode. I've opened microsoft/TypeScript#18492 to track this. I'm tried putting together a workaround but was not able to come up with one. Someone on the TS team may have a better idea on what to do here

Closing as upstream

@mjbvz mjbvz closed this as completed Sep 14, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 14, 2017

Hey @cwtuan, as a workaround try adding:

        "paths": {
            "axios": [
                "node_modules/axios/index.d.ts"
            ]
        }

to the src/tsconfig.json. I believe the alternative is to copy the axios/index.d.ts into src/typings

@cwtuan
Copy link
Author

cwtuan commented Sep 15, 2017

tsconfig.json:

{
	"compilerOptions": {
		"module": "amd",
		"moduleResolution": "classic",
		"noImplicitAny": false,
		"removeComments": false,
		"preserveConstEnums": true,
		"target": "es5",
		"sourceMap": false,
		"experimentalDecorators": true,
		"declaration": true,
		"paths": {
			"axios": [
				"node_modules/axios/index.d.ts"
			]
		}
	}
}

➜ cat "node_modules/axios/index.d.ts"

export interface AxiosTransformer {
  (data: any): any;
}

export interface AxiosAdapter {
  (config: AxiosRequestConfig): AxiosPromise;
}

export interface AxiosBasicCredentials {
  username: string;
  password: string;
}
......

But it still not work

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
engineering VS Code - Build / issue tracking / etc. javascript JavaScript support issues
Projects
None yet
Development

No branches or pull requests

2 participants