You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new in typescript and got stuck on "Uncaught Error: Cannot find module 'fs'" error..
Don't understand how to reference fs module (as I understand it should be part of NodeJs, but it is not found..)
My example code is:
import { loadContext } from "@utils/env";
import { logger } from "@utils/logger";
import { setupPnp } from "@utils/odata";
// import * as fs from "fs"; // <- tried to load like this
const fs = require("fs"); // and like this
import rtfToHTML from "@iarna/rtf-to-html";
loadContext()
.then(() => {
setupPnp();
const container = document.getElementById("example-cewp-container");
const rtfString = "{\\rtf1\\ansi\\deff0 hi \\b there\\b0 \\ul there \\ulnone\\i there is\\i0\\par }";
rtfToHTML.fromString(rtfString, (err, html) => {
console.log(html);
// This works ok, prints a document containing:
// <p>hi <strong>there</strong> <u>there </u><em>there</em></p>
});
rtfToHTML.fromStream(fs.createReadStream(`C:\qdr_template_en.rtf`), (err, html) => { // <----- Uncaught Error: Cannot find module 'fs'
// rtfToHTML.fromStream(fs.createReadStream("http://sppp/sites/site/web/Shared%20Documents/qdr_template_en.rtf"), (err, html) => { // not sure if it works by url..
console.log("html");
});
})
.catch(logger.error);
fs module is the Node.js one (runs on a server, not in a browser).
When you bundle a solution for the frontend you can't use server side modules. That's why the error, as the generator's solutions is client side browser apps targeted.
Greetings Andrew!
Want to read rtf template and then create modified report in sp library.
https://www.npmjs.com/package/@iarna/rtf-to-html
https://github.com/iarna/rtf-to-html
I'm new in typescript and got stuck on "Uncaught Error: Cannot find module 'fs'" error..
Don't understand how to reference fs module (as I understand it should be part of NodeJs, but it is not found..)
My example code is:
Best regards, Gennady
The text was updated successfully, but these errors were encountered: