【问题标题】:error TS2307: Cannot find module '@microsoft/microsoft-graph-client'错误 TS2307:找不到模块“@microsoft/microsoft-graph-client”
【发布时间】:2018-01-22 11:42:33
【问题描述】:

我对 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 在“@microsoft/microsoft-graph-client”上提供了 index.d.ts 的正确路径作为工具提示。

有人可以帮忙吗?我需要迁移到旧类型吗?

【问题讨论】:

  • 您是否仍然收到此错误?我已经使用最新版本的 typescript (3.3.3) 和 @microsoft/microsoft-graph-client (1.4.0) 进行编译,它对我来说很好。
  • 该错误已稍后修复。我没有问题了。

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


【解决方案1】:

尝试这样做:

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

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

【讨论】:

  • 感谢您的帮助,但不幸的是,这不起作用。在检查了所需文件的确切位置后,我尝试了以下操作:“typeRoots”:[“node_modules/@types”、“node_modules/@microsoft/microsoft-graph-client/lib/src/inde‌​x.d.ts”、“ node_modules/@microsoft/microsoft-graph-types/microsoft-graph.d.ts" ] 这是我当前对模块的调用: import {Client as GraphClient} from '@microsoft/microsoft-graph-client';从“@microsoft/microsoft-graph-types”导入 * 作为 MicrosoftGraph
猜你喜欢
  • 2018-03-14
  • 2017-01-06
  • 1970-01-01
  • 2016-08-29
  • 2018-08-29
  • 2017-03-30
  • 2019-07-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多