Closed aditya-manit closed 1 year ago
I am trying to fetch data to built a chart from an API, but I cannot add any imports to chart files (eg: area-simple.js)
area-simple.js
On adding import axios from 'axios'; Its giving me error: SyntaxError: Cannot use import statement outside a module
import axios from 'axios';
SyntaxError: Cannot use import statement outside a module
I have tried using require but then I am getting: On adding const axios = require('axios'); It giving me error: ReferenceError: require is not defined
const axios = require('axios');
ReferenceError: require is not defined
I am kinda new to webpack, Can someone please guide me to the correct way to call an api and use its data in area-simple.js file or any other file.
I don't know if you have solved this problem. For simplicity, it's suggested to use the native fetch, which needs no third-party library.
fetch
I am trying to fetch data to built a chart from an API, but I cannot add any imports to chart files (eg:
area-simple.js
)On adding
import axios from 'axios';
Its giving me error:SyntaxError: Cannot use import statement outside a module
I have tried using require but then I am getting: On adding
const axios = require('axios');
It giving me error:ReferenceError: require is not defined
I am kinda new to webpack, Can someone please guide me to the correct way to call an api and use its data in
area-simple.js
file or any other file.