【问题标题】:How do I force a devDependency to use the dependency in AWS-CDK如何强制 devDependency 使用 AWS-CDK 中的依赖项
【发布时间】:2022-02-17 22:41:44
【问题描述】:

我正在尝试使用具有核心依赖项的某个库,但是当我传递他需要的那种类型的对象时,由于子库正在使用他自己的节点模块作为路径,因此会引发错误。

这是我导入的对象以及我如何传递它:

import { Construct } from "@aws-cdk/core";
import { CfnDataSource } from "@aws-cdk/aws-quicksight";
...
constructor(scope: Construct, id: string) {
...
this.quickSightCdk = new CfnDataSource(scope, 'QuickSight', {
...

但它会抛出一个不匹配的错误,因为 quickisight 在它自己的节点模块中查找对象:

Argument of type 'import("C:/git/monorepo/aws/node_modules/@aws-cdk/core/lib/construct-compat").Construct' is not assignable to parameter of type 'import("C:/git/monorepo/aws/node_modules/@aws-cdk/aws-quicksight/node_modules/@aws-cdk/core/lib/construct-compat").Construct'.

并排:

'import("C:/git/monorepo/aws/node_modules/@aws-cdk/core/lib/construct-compat").Construct'
'import("C:/git/monorepo/aws/node_modules/@aws-cdk/aws-quicksight/node_modules/@aws-cdk/core/lib/construct-compat").Construct'   

我尝试在参数上传递“this”,但它不起作用,

TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'. Type 'MyStack' is not assignable to type 'Construct'

我已经尝试将这两个库更新到最新版本,但没有成功。 有什么建议吗?

【问题讨论】:

  • 有什么更新吗?不要让你的问题悬而未决。

标签: amazon-web-services npm aws-cdk


【解决方案1】:

您可能没有将作用域和构造 ID 传递给 super 构造函数,或者没有从 Stack 继承。它应该是这样的:

class MyStack extends Stack {

  constructor(scope: Construct, id: string) {
    super(scope, id);
  
    this.quickSightCdk = new CfnDataSource(this, 'QuickSight', {...});
}

请注意,如果您希望在堆栈中创建它们,则绝对应该将 this 作为构造的范围传递。

【讨论】:

  • 不确定您是否在我编辑之前回答,但我确实尝试传递“this”,并得到Type 'MyStack' is not assignable to type 'Construct'。编辑:抱歉错过了 super 部分,但是是的,我已经将范围传递给 super()
  • 分享更多代码。你是从 Stack 继承的吗?您的 CDK 包的版本是什么?
猜你喜欢
  • 2021-12-18
  • 1970-01-01
  • 2021-07-25
  • 2022-10-05
  • 2020-11-08
  • 1970-01-01
  • 2019-11-04
  • 2021-12-18
  • 1970-01-01
相关资源
最近更新 更多