0

I have a component I am trying to simplify. I am removing some functions from the file to put into another folder to help make the code more readable.

this is an example of one of the functions I'm moving,

export default function generatemwapGraphData(items) {
    let total = {
      mwap: 0,
  ..  };
    let count = items.length;
  
    items.forEach((item) => {
      total["mwap"] += item["mwap"] / count;
     ...
    });
  
    let finalData = [];
  
    Object.keys(total).forEach((exp) => {
      finalData.push({
        expression: exp,
        Percentage: +(total[exp] * 100).toFixed(2),
      });
    });
  
    return finalData;
  }

Now when I take this function and try to import it like this,

import generateExpressionsGraphData from "components/dashboard/Mood/functions/generateExpressionsGraphData"

It returns an error of

Attempted import error: 'generateExpressionsGraphData' is not exported from 'components/dashboard/Mood/functions/generateExpressionsGraphData' (imported as 'generateExpressionsGraphData').

Surely this should be fine?

Thanks

4
  • 1
    This should've worked. You should check your file names and file path and see if they are correct. Commented Feb 16, 2021 at 6:20
  • please double check the component name and file generatemwapGraphData or generateExpressionsGraphData Commented Feb 16, 2021 at 6:21
  • It is the sdame, just changed it to anonymise it a bit Commented Feb 16, 2021 at 6:29
  • Can you create a reproducible example in codepen or codesandbox ? Commented Feb 16, 2021 at 6:37

1 Answer 1

1

You haven't exported the function from that file. Note that if you use export default you have to import it like import something from file and when you use just export something you have to import it in curly braces like import {something} from file. Also check the file name that has to be imported identical.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.