错误TS2307:找不到模块' @ microsoft / microsoft-graph-client'

时间:2018-01-22 11:42:33

标签: typescript gulp microsoft-graph typescript-typings typescript2.0

我对Typescript非常陌生,所以如果这很明显我很抱歉。几个小时的谷歌搜索并没有为我解决。

我尝试将模块@ microsoft / microsoft-graph-client导入我的打字稿,但是它会引发以下错误:

(3,37): error TS2307: Cannot find module '@microsoft/microsoft-graph-client'.

这是我的package.json

{
 "name": "teams-app-1",
 "version": "1.0.0",
 "description": "Generate a Microsoft Teams application.",
 "repository": {
  "type": "git",
  "url": "https://some.url.com/_git/teams_app"
 },
 "license": "UNLICENSED",
 "private": true,
 "scripts": {
  "start": "node dist/server.js",
  "build": "gulp build",
  "postinstall": "bower install"
 },
 "engines": {
  "node": "8.9.x"
 },
 "dependencies": {
  "body-parser": "1.17.2",
  "browser-request": "0.3.3",
  "express": "4.15.3",
  "express-session": "1.15.4",
  "gulp": "3.9.1",
  "gulp-inject": "4.2.0",
  "gulp-util": "3.0.8",
  "gulp-zip": "4.0.0",
  "morgan": "1.8.2",
  "msal": "0.1.1",
  "nodemon": "1.11.0",
  "path": "^0.12.7",
  "run-sequence": "1.2.2",
  "superagent": "^3.8.2",
  "ts-loader": "2.3.2",
  "typescript": "^2.6.2",
  "webpack": "2.7.0"
 },
 "devDependencies": {
  "@microsoft/microsoft-graph-client": "^1.0.0",
  "@microsoft/microsoft-graph-types": "^1.1.0",
  "@types/body-parser": "1.16.4",
  "@types/express": "4.0.36",
  "@types/express-session": "0.0.32",
  "@types/morgan": "1.7.32",
  "@types/superagent": "^3.5.6"
 }
}

我的tsconfig.json:

{
 "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "moduleResolution": "node",
    "noImplicitAny": false,
    "strictNullChecks": true,
    "jsx": "react",
    "sourceMap": true,
    "typeRoots": [
        "node_modules/@types", 
        "node_modules/@microsoft"
    ]
 },
 "exclude": [
    "node_modules",
    "dist/web/assets/bower"
 ]
}

它也尝试删除属性typeRoots,但它也不起作用。

这是我尝试调用的行

 import {Client as GraphClient} from "@microsoft/microsoft-graph-client";

存储在@types中的模块已成功加载,但找不到@microsoft。奇怪的是:VisualStudio Code为index.d.ts提供了正确的路径,作为" @ microsoft / microsoft-graph-client"上的工具提示。

有人可以帮忙吗?我是否需要迁移到旧版本?

1 个答案:

答案 0 :(得分:0)

尝试这样做:

"typeRoots": [
    "node_modules/@types", 
    "node_modules/@microsoft/microsoft-graph-types/microsoft-graph.d.ts"
 ]

我认为问题是他们没有使用index.d.ts,如果在typeRoots中指定文件夹,编译器就会查找该文件。