我已经使用此命令安装了 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/