Javascript not detected when trying to import a script in a new project?

58 Views Asked by At

I have a script in my project, I use it to do the logic of my app, then the project I am working on has to be imported in another project using yalc, I did not write the code of this project, but I think I got it, he takes my UI and render them, and take my script and add it in the bottom, like that :

import fs from "fs";

const myScriptPath =
  "./urlwherethereismyminscriptjs/public/script.min.js";

var contentOfScript;
if (!fs.existsSync(myScriptPath)) {
  console.log("File " + myScriptPath + " not found");
} else {
  contentOfScript = fs.readFileSync(myScriptPath, "utf8");
}

function getComponent(cmp) {
  if (cmp) {
    const element = (
      <>
        <Cmp blocks={cmp.blockList} items={cmp.menuItemList} />
        <script
          type="text/javascript"
          dangerouslySetInnerHTML={{ __html: contentOfScript }}
        />
      </>
    );
    const styleSheet = new ServerStyleSheet();
    const theJsx = styleSheet.collectStyles(element);
    return styleSheet.interleaveWithNodeStream(renderToNodeStream(theJsx));
  }
  return null;
}

In my inspector I see the script imported correctly, but not working, what is not working in it ?everything, I got error like this :

exports not defined
window not defined
document not defined

It seems like nothing is defined right there.

Anyone can help me with a solution and I would greatly appreciate it.

0

There are 0 best solutions below