question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fs in _document.js

See original GitHub issue

[x] I have searched the issues of this repository and believe that this is not a duplicate.

I try to use fs in _document.js, developement & build process is success, but when I tried to run in production mode. I got the message.

Error: EBADF: bad file descriptor, fstat

My understand. _document.js can use on _document.js because it only runs on server-side only right?

What else, I need to config

My Environment

Tech Version
next 5.1
node 8.9.3
OS OSX
browser Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, May 9, 2018

@comus in development we do bundle it for the client side, the reason for this is hot reloading on _document.js

1reaction
comuscommented, May 9, 2018

oh, sorry, seems like next.config.js must add fs: empty for import fs, not sure how it works

module.exports = {
  webpack: function (config, { isServer }) {
    config.node = {
      fs: 'empty'
    }
    return config
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

File system | Node.js v19.3.0 Documentation
The fs/promises API provides asynchronous file system methods that return promises. The promise APIs use the underlying Node.js threadpool to perform file ...
Read more >
Node.js File System Module - W3Schools
The fs.readFile() method is used to read files on your computer. ... The fs.appendFile() method appends specified content to a file.
Read more >
Fs - node - Read the Docs
writeFile(filename, data[, options], callback) Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or...
Read more >
How To Work with Files using the fs Module in Node.js
With Node.js, you can programmatically manipulate files with the built-in fs module. The name is short for “file system,” and the module ...
Read more >
Node.js fs.readdir() Method - GeeksforGeeks
The fs.readdir() method is used to asynchronously read the contents of a given directory. The callback of this method returns an array of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found