TypeScript import paths

匿名 (未验证) 提交于 2019-12-03 01:35:01

问题:

I am building a grafana plugin using TypeScript, same as here.

The folder structure looks like:

Unsurprisingly I cannot compile my TypeScript plugin because in module.ts

import { MetricsPanelCtrl } from 'app/plugins/sdk';

All the examples use the path 'app/plugins/sdk' even though app is nowhere near them in the directory structure.

So how do they do it?

I tried changing my import path to '../../../../public/app/plugins/sdk' and that gets further, but then get 1000s of erros about the other modules not compiling like:

Running "typescript:build" (typescript) task >> ../../../public/app/core/components/code_editor/code_editor.ts(30,20): error TS2307: Cannot find module 'app/core/config'. >> ../../../public/app/core/components/code_editor/code_editor.ts(31,17): error TS2307: Cannot find module 'brace'. 

回答1:

Missed the bottom of the README:

The Grafana SDK Mocks package contains mocks for the Grafana classes that a plugin needs to build in TypeScript...

npm install --save-dev grafana/grafana-sdk-mocks

Place the directive at the top of all your TypeScript files:

///<reference path="../node_modules/grafana-sdk-mocks/app/headers/common.d.ts" />



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!