I use standard nextron (Next + electron.js) to jump start my project (https://github.com/saltyshiomix/nextron)
In one particular case, I need to read a file template.html
to variable (String). so I think I'll use fs.readFileSync()
When I use import fs from "fs"
, the compiler complains that fs
is not available. (refer to this Module not found: Can't resolve 'fs' in Next.js application)
The accepted answer on that thread, recommends me to update the next.config.js
file into:
/// I need this to load image from static files
const withImages = require('next-images')
module.exports = withImages({
webpack: (config, { isServer }) => {
// Fixes npm packages that depend on `fs` module
if (!isServer) {
config.node = {
fs: 'empty'
}
}
return config
}
})
But the solution doesn't work for me.
import fs from 'fs'
const generatePDF = () => {
let content = fs.readFileSync("./template.html")
}
What's wrong here?