Import Javascript modules in Yeoman Excel add-in project

Viewed 36

I'm trying to create an Excel add-in with Yeoman generator. In the excel_project/src/taskpane/taskpane.js file I'd like to call the 'fs' library. When I execute taskpane.js alone on my terminal, everything works fine. However, when I launch the whole Excel project (npm start on my terminal) I have a module import error (see image). It's as if modules couldn't be imported in the Excel add-in... Does anyone have any ideas ? Thanks for your help.

Here is the taskpane.js file, like it is created by Yeoman. I've just added const fs = require('fs'); // this gives the error

Office.onReady((info) => {
  if (info.host === Office.HostType.Excel) {
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = run;
  }
});

export async function run() {
  try {

    const fs = require('fs'); // this gives the error

    
    await Excel.run(async (context) => {

      const range = context.workbook.getSelectedRange();
      let text = document.querySelector('textarea').value;

      // Read the range address
      range.load("address");

      // Update the fill color
      range.format.fill.color = "yellow";

      await context.sync();
      console.log(`The range address was ${range.address}.`);
    });
  } catch (error) {
    console.error(error);
  }

}

Here is the error message: enter image description here

0 Answers
Related