You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/02/26 02:44:09 UTC
[GitHub] [echarts] lz1998 commented on pull request #14352: fix: import theme error
lz1998 commented on pull request #14352:
URL: https://github.com/apache/echarts/pull/14352#issuecomment-786371835
This is my code. Line `require("echarts/theme/vintage")` report this error
```javascript
import {createCanvas} from 'canvas'
import * as echarts from 'echarts'
import Express from 'express'
import {Request, Response} from 'express'
// 导入主题
require("echarts/theme/vintage")
// 生成图片
function generateImage(options: any, width: number, height: number, theme: string) {
console.log("GENERATE IMAGE")
console.log(`WIDTH: ${width}`)
console.log(`HEIGHT: ${height}`)
console.log(`THEME: ${theme}`)
console.log(`OPTIONS: ${JSON.stringify(options)}`)
const canvas = createCanvas(width, height) as any
const ctx = canvas.getContext('2d')
ctx.font = '12px'
echarts.setCanvasCreator(() => canvas)
const chart = echarts.init(canvas, theme)
options.animation = false
chart.setOption(options)
return (chart.getDom() as any).toBuffer()
}
const express = require('express')
const app = Express()
app.use(express.json())
const imgController = (req: Request, res: Response) => {
console.log("RECV REQ")
let options = req.query.options || req.body
if (typeof options === 'string') {
options = JSON.parse(options)
}
let width = parseInt(req.query.width || options.width || 1024)
let height = parseInt(req.query.height || options.height || 768)
let theme = req.query.theme || options.theme || 'dark'
res.header("Content-Type", "image/png")
res.send(generateImage(options, width, height, theme))
}
app.post('/', imgController)
app.get('/', imgController)
const PORT = process.env.PORT || 3000
app.listen(PORT)
console.log("echarts started port:" + PORT)
```
Error
```bash
/Users/lz1998/WebstormProjects/ssr-echarts/node_modules/echarts/lib/echarts.js:44
export * from './export/core';
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1054:16)
at Module._compile (internal/modules/cjs/loader.js:1102:27)
at Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Object.require.extensions.<computed> [as .js] (/Users/lz1998/WebstormProjects/ssr-echarts/node_modules/ts-node/src/index.ts:1045:43)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at /Users/lz1998/WebstormProjects/ssr-echarts/node_modules/echarts/theme/vintage.js:29:26
at Object.<anonymous> (/Users/lz1998/WebstormProjects/ssr-echarts/node_modules/echarts/theme/vintage.js:34:3)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org