我使用chartjs-node-canvas和chartjs将图形配置渲染为图像,因此在安装它之后,我尝试了以下操作:
import { ChartJSNodeCanvas } from 'chartjs-node-canvas';
const chartCallback = (ChartJS) => {
ChartJS.defaults.global.elements.rectangle.borderWidth = 2;
};
const canvasRenderService = new ChartJSNodeCanvas({
width,
height,
chartCallback,
});
但在创建新的ChartJSNodeCanvas时出现以下错误:
Error: Cannot find module 'canvas'
at Function.webpackEmptyContext [as resolve] (http://localhost:4200/main.js:131373:10)
at freshRequire (http://localhost:4200/main.js:21530:69)
at new ChartJSNodeCanvas (http://localhost:4200/main.js:21592:50)
at ChartImageService._callee2$ (http://localhost:4200/main.js:127066:39)
at tryCatch (http://localhost:4200/main.js:115133:17)
at Generator.invoke [as _invoke] (http://localhost:4200/main.js:115347:22)
at Generator.next (http://localhost:4200/main.js:115185:21)
at http://localhost:4200/main.js:127002:67
at new ZoneAwarePromise (http://localhost:4200/polyfills.js:7278:21)
at __awaiter (http://localhost:4200/main.js:126981:10) {code: 'MODULE_NOT_FOUND', stack: 'Error: Cannot find module 'canvas'
at Fun…ter (http://localhost:4200/main.js:126981:10)', message: 'Cannot find module 'canvas''}
我试着重新安装npm,重新生成npm,删除package-lock.json...但是不起作用。有什么想法吗?
我用的是电子Angular
2条答案
按热度按时间l7mqbcuq1#
在https://www.npmjs.com/package/chartjs-node-canvas上,有以下注解:
NodeJS 版本
这受到上游依赖关系canvas的限制。
因此,如果运行以下命令,问题应该可以解决:
64jmpszr2#
打开新终端并写入npm命令以安装chartjs-node-canvas模块