javascript – import axios in another js file-ThrowExceptions

Exception or error:

It’s a flask based project, and I’d like to import axios into another js file.

in my figuresHelper.js, I’d like to import axios to fetch data from api service

import {PieChart} from './pie-chart-module.js'
import * as axios from './axios.js'

let figuresHelper = {
    init: function(){ console.log('init something'); axios.get('url').... }
export {figuresHelper}

and the code in my index.html

<script type="module">
    import {figuresHelper} from "../static/js/figuresHelper.js";

it raises error

Uncaught TypeError: Cannot set property 'axios' of undefined
    at webpackUniversalModuleDefinition

I’m not allowed to use vue in this project so far and this problem kills me

How to solve:

you can’t just

export const figuresHelper = () => {
    console.log('init something'); 

then in html?

<script type="module">
    import {figuresHelper} from "../static/js/figuresHelper.js";

Leave a Reply

Your email address will not be published. Required fields are marked *