我在尝试在我正在开发的 Grafana 数据源插件中导入 crypto-js 库时遇到问题。
我收到以下异常:
Error: (SystemJS) Cannot set property 'CryptoJS' of undefined TypeError: Cannot set property 'CryptoJS' of undefined at Object.create.F (http://localhost:3000/public/plugins/grafana-my-datasource/external/crypto-js.js?bust=1493397621246:25:20) at execute (http://localhost:3000/public/plugins/grafana-my-datasource/external/crypto-js.js?bust=1493397621246:27:6) Error loading http://localhost:3000/public/plugins/grafana-my-datasource/module.js
我在 datasouce.js 中有这个:
import _ from "lodash";
import moment from 'moment';
import CryptoJS from './external/crypto-js';
export class GenericDatasource {
.......
在 Gruntfile.js 中:
externals: {
cwd: 'src',
expand: true,
src: ['**/external/*'],
dest: 'dist'
}
有什么想法吗?
最佳答案
需要检查两件事:
Grafana 是否找到 js 文件?您可以导航至 http://localhost:3000/public/plugins/grafana-my-datasource/external/crypto-js.js在浏览器中获取 JavaScript 文件?
您导入正确吗? CryptoJS 是默认导入吗?您可以尝试:
从'./external/crypto-js'导入*作为CryptoJS;
- 有一个GitHub Issue here about ES6 and CryptoJS它展示了如何仅导入一种算法。
关于javascript - 可以在 Grafana 数据源库中导入外部 JavaScript 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43686842/