SyntaxError: Unexpected token export while importing
See original GitHub issueHi I am trying to use the lightweight chart on my Nextjs - React application but it keeps returning this error! Do you have any idea what is wrong with my component?
I thought maybe it’s because of server-side rendering but I get the error as soon as I import it in my component!
import React, { useRef } from 'react';
import { createChart } from 'lightweight-charts';
const Index = () => {
const chartRef = useRef(null);
const chart = createChart(chartRef.current, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
{ time: '2019-04-11', value: 80.01 },
{ time: '2019-04-12', value: 96.63 },
{ time: '2019-04-13', value: 76.64 },
{ time: '2019-04-14', value: 81.89 },
{ time: '2019-04-15', value: 74.43 },
{ time: '2019-04-16', value: 80.01 },
{ time: '2019-04-17', value: 96.63 },
{ time: '2019-04-18', value: 76.64 },
{ time: '2019-04-19', value: 81.89 },
{ time: '2019-04-20', value: 74.43 },
]);
return (
<>
<div ref={chartRef}></div>
</>
);
};
export default Index;
Error:
export { CrosshairMode, LineStyle, LineType, PriceScaleMode, createChart, isBusinessDay, isUTCTimestamp, version };
^^^^^^
SyntaxError: Unexpected token export
at Module._compile (internal/modules/cjs/loader.js:720:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/front-next/node_modules/lightweight-charts/index.js:6:19)
at Module._compile (internal/modules/cjs/loader.js:777:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.lightweight-charts (/front-next/_next/server/static/development/pages/index.js:197:18)
at __webpack_require__ (/front-next/_next/server/static/development/pages/index.js:23:31)
at Module../pages/home/index.js (/front-next/_next/server/static/development/pages/index.js:109:76)
/front-next/node_modules/lightweight-charts/dist/lightweight-charts.esm.development.js:10998
export { CrosshairMode, LineStyle, LineType, PriceScaleMode, createChart, isBusinessDay, isUTCTimestamp, version };
^^^^^^
More info about error :
/front-next/node_modules/lightweight-charts/dist/typings.d.ts
Error:(92, 3) TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
Error:(516, 16) TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Getting Unexpected Token Export - javascript - Stack Overflow
This error is suggesting that either webpack or babel are not working correctly, as export is only available in ES6, and those modules...
Read more >SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >How to fix SyntaxError: Unexpected token 'export' in JavaScript?
In this article, we are going to see How to fix SyntaxError: Unexpected token 'export' in JavaScript? and what are Es6 modules.
Read more >How to Solve Unexpected Token 'export' Error in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >SyntaxError: Unexpected token 'export' - Abhishek Kumar
In case you are getting error like 'Unexpected token export' while starting the server, then export like below in schema.js
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
When I import it in didMount it seems correct but why is that?
The problem is solved - I had to import the charts on component did mount- the code above is updated