Argument of type 'this' is not assignable to parameter of type 'Construct'.
See original GitHub issueIf you get this error, please follow these instructions:
- Make sure all CDK modules in your
package.json
file have the exact same version. - Nuke your local
node_modules
- Run
npm install
(oryarn install
).
See #542
Reproduction Steps
-
Utilize any two separate versions of a @aws-cdk/* package. I suspect the source of error is if any two separate files are used when pulling the source or definition of the
Construct
class. Typically, this has been remarked as an item of two separate @aws-cdk/* package versions in yourpackage.json
OR due to a package version range specified inpackage.json
where the team has updated the package version recently. I’ll introduce a new suspected cause in my notes. -
Upon running TSC when utilizing constructing any
Construct
utilizing two separate versions of theConstruct
file (even if they syntactically 100% the exact same contents), the referenced error will occur:Argument of type 'this' is not assignable to parameter of type 'Construct'.
Note: This refers to the usage of new SomeConstruct(someConstructReference, ...)
where SomeConstruct
references some different source file for defining Construct
vs. what someConstructReference
references for its definition of Construct
, even if the two source files are 100% identical.
Environment
- CLI Version : 1.30
- Framework Version: 1.30
- OS : Windows
- Language : TypeScript
Other
We had decent luck resolving these issues due to errors relating to mismatched versions. This breaks, however, when utilizing some package depending on CDK as a global since the dependencies of the global (i.e. some different CDK file defining Construct) are not installed into the dependee module (i.e. a file that ultimately depends on some other CDK file defining Construct).
Please see this: https://www.sitepoint.com/solve-global-npm-module-dependency-problem/
I have an idea to resolve, will post a follow-up if this yields luck. Suggest dropping a note into your docs regarding any team trying to build a global module that depends on CDK (where dependees also depend on CDK in some way).
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top GitHub Comments
@maxpaj you should always pin your CDK versions to exactly one version and not use the caret
^
.Thanks for reporting this! We are well aware that this is still a major issue in consuming the CDK and publishing modules, and working hard to solve it.
See https://github.com/aws/aws-cdk-rfcs/pull/122