简体   繁体   English

MongDB找不到Promise类型定义

[英]MongDB cannot find Promise type definition

I have created a new project, installed few type definitions (from DefinitelyTyped) and made a basic src/go.ts file. 我创建了一个新项目,安装了几个类型定义(来自DefinitelyTyped)并创建了一个基本的src/go.ts文件。

Whenever I transpile the code, I get a ton of TS2304: Cannot find name 'Promise' errors! 每当我转换代码时,我得到了大量的TS2304: Cannot find name 'Promise'错误!
The ./typings/mongodb/index.d.ts is referencing the Promise , but the compiler does not seem to find that. ./typings/mongodb/index.d.ts引用了Promise ,但编译器似乎没有找到它。
Please note that I have dt~promise installed as well. 请注意,我已经dt~promise安装好了。

Screenshot (Errors on the left side, type definitions installed and the app code are on the right) 屏幕截图 (左侧错误,已安装类型定义,应用程序代码位于右侧)

Content of typings.json : typings.json内容:

{
  "globalDependencies": {
    "dotenv": "registry:dt/dotenv#2.0.0+20160327131627",
    "express": "registry:dt/express#4.0.0+20160708185218",
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20160805091045",
    "mime": "registry:dt/mime#0.0.0+20160316155526",
    "mongodb": "registry:dt/mongodb#2.1.0+20160602142941",
    "mongoose": "registry:dt/mongoose#4.5.4+20160807120805",
    "mongoose-promise": "registry:dt/mongoose-promise#4.5.4+20160720003345",
    "node": "registry:dt/node#6.0.0+20160807145350",
    "promise": "registry:dt/promise#7.1.1+20160602154553",
    "serve-static": "registry:dt/serve-static#0.0.0+20160606155157"
  }
}

Any thoughts? 有什么想法吗?

I've experienced the same issue (more or less, using @types instead of typings) and was able to solve it by installing the type definitions for CoreJS . 我遇到了同样的问题(或多或少,使用@types而不是typings)并且能够通过安装CoreJS的类型定义来解决它。

Screenshots 截图

Apologize for linking to a library, this is my first post so I am unable to provide more than two links per post. 为链接到图书馆道歉,这是我的第一篇文章,因此我无法为每个帖子提供两个以上的链接。

Image explanations: 图片说明:

  • First screenshot shows similar error, type definition file for MongoDB is unable to find 'Promise'. 第一个截图显示类似的错误,MongoDB的类型定义文件无法找到'Promise'。
  • Install type definitions for CoreJS. 安装CoreJS的类型定义。 Note that I am getting my type definitions through NPM and not Typings. 请注意,我通过NPM获取我的类型定义,而不是打字。 So to do something similar in Typings you would run something like: 所以要在Typings中做类似的事情,你会运行如下:
    • typings install dt~core-js --save --global
  • Third screenshot shows build command with no errors on output 😁 第三个屏幕截图显示了构建命令,输出no没有错误

I hope this resolves your issue. 我希望这能解决你的问题。

I had the same issue installing lastest version of mongodb and mongoose typings. 我有同样的问题安装最新版本的mongodb和猫鼬类型。

The new definition file for mongodb assumes you are using ES6 promise so if you change the target of the typescript compiler in the tsconfig.json to es6 it should do the trick : mongodb的新定义文件假设您正在使用ES6承诺,因此如果您将tsconfig.json中的tsconfig.json编译器的target更改为es6它应该可以解决这个问题:

tsconfig.json: tsconfig.json:

{
    "compilerOptions": {
        ...
        "target": "ES6",
        ...
    }
}

For typings: typings install core-js --ambient --save . 对于打字: typings install core-js --ambient --save It works for me. 这个对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到“节点”的类型定义文件 - Cannot find type definition file for 'node' 构建:找不到“节点”的类型定义文件 - Build:Cannot find type definition file for 'node' 找不到'core-js'的类型定义文件 - Cannot find type definition file for 'core-js' “找不到‘async’的类型定义文件。TS2688” - "Cannot find type definition file for 'async'. TS2688" npm install => 找不到“节点”的类型定义文件 - npm install => Cannot find type definition file for 'node' 无法在Azure CosmosDB中连接到Mongdb - Cannot connect to Mongdb in azure cosmosdb 每次我尝试部署函数时,我都会收到“找不到类型定义文件...” - Everytime I try to deploy functions I get "Cannot find type definition file for ..." 打字稿错误TS2688:找不到“ .AppleDouble”的类型定义文件 - Typescript error TS2688: Cannot find type definition file for '.AppleDouble' TS2688:找不到安装了@ types / node的“ node”的类型定义文件 - TS2688: Cannot find type definition file for 'node' with @types/node installed Elastic Beanstalk“错误 TS2688:找不到‘节点’的类型定义文件。” - Elastic Beanstalk "error TS2688: Cannot find type definition file for 'node'."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM