简体   繁体   English

使用ES6导入节点模块时找不到模块的声明文件

[英]Could not find a declaration file for module while importing a node module using ES6

I have setup loopback 4 and trying to write a new controller for my Braintree API payments. 我已经设置了环回4,并试图为我的Braintree API付款编写一个新的控制器。 I have installed the Braintree npm module and using 我已经安装了Braintree npm模块并使用

import {braintree} from 'braintree';

to import into a controller and use in an endpoint. 导入控制器并在端点中使用。 But it is throwing me following error: 但这使我产生以下错误:

*src/controllers/braintree.controller.ts:23:25 - error TS7016: Could not find a declaration file for module 'braintree'. '/home/oem/Learning/learn-loopback/my-todo-app/node_modules/braintree/index.js' implicitly has an 'any' type.
Try `npm install @types/braintree` if it exists or add a new declaration (.d.ts) file containing `declare module 'braintree';*`

When I try the es5 way of importing it is working fine. 当我尝试导入es5的方式时,它工作正常。

Not sure how to fix this. 不确定如何解决此问题。

The braintree type does not seem to exist yet. 脑树类型似乎还不存在。 So here you have 2 possibilities: 因此,这里有两种可能性:

  • You create a type file as suggested in the error, but you need to have a good knowledge of the braintree library. 您按照错误中的建议创建类型文件,但是您需要对Braintree库有充分的了解。
  • Replace import {braintree} from 'braintree'; import {braintree} from 'braintree';替换import {braintree} from 'braintree'; with const braintree = require('braintree'); const braintree = require('braintree'); but you won't have access to all the typescript magic, so be careful when manipulating this library. 但您无法访问所有打字稿魔术,因此在操作该库时要小心。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM