'importing fs in nodejs

hello everyone!

I'm trying to import fs module in nodejs

first I was using require to import it like this

const fs = require('fs');

It was working fine for a while but suddenly stopped working and I'm getting this Error now

Error: Uncaught ReferenceError: require is not defined

so I tried using Import to import it like this

import fs from 'node:fs'

and I tried many other ways for importing it using import and I'm getting this two Errors

Error1: GET node:fs net::ERR_UNKNOWN_URL_SCHEME

Error2: Uncaught TypeError: Failed to resolve module specifier "fs". Relative references must start with either "/", "./", or "../".

Is there any other ways for importing module in Nodejs? or the problem is my code? I've had many problems with fs module in nodejs, I've tried googling and I couldn't find any solution for this one, I appreciate you guys helping me.

I'm using it to load a local file in Electronjs

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source