0
const fs = require('fs');
let initialValue = '';

fs.readFile('../previewFirst.txt', (err, data) => {
   if (err)
      throw err;
   console.log(data.toString());
   initialValue = data.toString();
});

I am using github codespaces, but I can't use require despite node.js being built in to codespace (or at least in my project it told me it had node.js)

The codespace should come with node.js, yet I can't use require.

My error: Module not found: Error: Can't resolve 'fs' in '/workspaces/codespaces-react/src/features'

I tried to edit the devcontainer, to see that node.js was, in fact, installed.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Does this answer your question? [Module not found: Error: Can't resolve 'fs' in](https://stackoverflow.com/questions/57161839/module-not-found-error-cant-resolve-fs-in). Look at your project's `package.json` – paulsm4 Jan 25 '23 at 22:21
  • @paulsm4 I think you can add node.js to the package.json file, but I'm not sure how to. – youlikecodingstackoverflow Jan 25 '23 at 22:26
  • No no NO! The error you cited, `Can't resolve 'fs'`, merely says you're missing the JavaScript module "fs" (which is why you can't "require" it). It sounds like you already *HAVE* NodeJS itself. Here's the documentation (which I presume you're already familiar with): https://docs.github.com/en/enterprise-cloud@latest/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/setting-up-your-nodejs-project-for-codespaces. Double-check your project's `package.json`. – paulsm4 Jan 25 '23 at 23:26
  • @paulsm4 Is nodeJS not included with fs? – youlikecodingstackoverflow Jan 26 '23 at 03:12

0 Answers0