-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import ECharts.js modules manually results in SyntaxError: Unexpected token 'export' error when running Jest #495
Comments
Things that I stumbled upon that I tried with no luck: |
what is your nodejs、typescript version? try to upgrade them! |
used typescript-version: 4.8.3 This maybe has something todo with ESM modules working different in TypeScript-context, what do you think?. |
Updated: fail ... the test was no longer loading echarts.. |
@NotSqrt Have you checked that with the example provided by me? Because I already tried a lot. |
@FibreFoX Sorry, fail ... my test was no longer loading echarts.. |
Related : apache/echarts#16709 |
I got a mock to work around the syntax error... my regular file is import EChartsReactCore from 'echarts-for-react/lib/core';
import * as echarts from 'echarts/core';
import {
BarChart,
LineChart,
PieChart,
} from 'echarts/charts';
import {
TitleComponent,
TooltipComponent,
ToolboxComponent,
GridComponent,
LegendComponent,
DataZoomComponent,
DataZoomInsideComponent,
DataZoomSliderComponent,
DatasetComponent,
TransformComponent
} from 'echarts/components';
import { LabelLayout, UniversalTransition } from 'echarts/features';
import { CanvasRenderer } from 'echarts/renderers';
echarts.use([
TitleComponent,
TooltipComponent,
ToolboxComponent,
GridComponent,
LegendComponent,
DataZoomComponent,
DataZoomInsideComponent,
DataZoomSliderComponent,
DatasetComponent,
TransformComponent,
BarChart,
LineChart,
PieChart,
LabelLayout,
UniversalTransition,
CanvasRenderer
]);
// subclass to use our bundle for echarts
export class EChartsReact extends EChartsReactCore {
static defaultProps = {
echarts
}
} Then, I can bypass the syntax error by not importing from
import EChartsReactCore from 'echarts-for-react/lib/core';
// subclass to use our bundle for echarts
export class EChartsReact extends EChartsReactCore {} And in my tests, I can activate It no longer uses a smaller bundle, but at least the tests can run .. |
But thats the problem, when using all the given instructions for the minimal bundle. Having this "replaced" with a mock, does not solve that problem, it just obfruscates it. I think the core problem comes from this ESM stuff, which might originate from apache/echarts#16709 (comment) (where I already posted something to make them aware). But even |
After loosing half a day of trying to have this working, there seems to be something broken when Jest is involved. The instructions in the README.md do not seem to be complete.
I have a fairly standard React v17 app (created via CRA), where I am using
echarts-for-react
.When having something like this, it results in Jest-tests not working:
Jest quits exploding with the following lines:
With these lines it works .... but why? What am I missing?
Just to be clear: it is only Jest here that seems to not work. When building my application, or running
yarn start
as normal, it works.Some parts of the
package.json
from my project.The text was updated successfully, but these errors were encountered: