typescript - 出现错误 : Cannot find module 'js-yaml'

标签 typescript yaml aws-cdk

我已经使用此命令安装了 js-yaml

npm i @types/js-yaml

我的package.json看起来像这样

"dependencies": {
  "@types/js-yaml": "^4.0.5",
  "aws-cdk-lib": "2.20.0",
  "constructs": "^10.0.0",
  "source-map-support": "^0.5.16",
  "ts-sync-request": "^1.4.1"
}

我的代码在 vscode 中没有显示任何错误

import * as yml from 'js-yaml';
...
const metricsServerManifestUrl = 'https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml';
const manifest = yml.loadAll(new SyncRequestClient().get(metricsServerManifestUrl));
cluster.addManifest('metrics-server', manifest);

但是当我尝试运行应用程序时遇到此错误

Error: Cannot find module 'js-yaml'

我该如何解决这个问题?

最佳答案

@types/js-yaml 仅包含 TypeScript 编译器用于验证代码的类型定义。但是,它不包含运行时所需的实际实现。

您应该安装npm install js-yaml --save

关于typescript - 出现错误 : Cannot find module 'js-yaml' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71823045/

相关文章:

typescript - 重载不能仅因返回类型而异

javascript - 我可以告诉 useMemo 跳过其依赖项数组中的空值吗?

c# - Azure DevOps YAML 管道失败并显示 "A sequence was not expected"

amazon-web-services - 如何为 CfnDistribution 添加 Route53 别名?

amazon-web-services - 使用 AWS CDK 配置 Lambda 加热器

typescript 通用类型断言

typescript - 如何检查字符串是否属于 TypeScript 中的类型?

java - 从命名的 yaml 属性列表中读取字符串数组作为常量?

python - 转储 yaml 时如何保留键值缩进

aws-cdk - 如何使用 aws cdk synth/deploy 显示堆栈跟踪