# How to use fs module?

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127>\
**Category:** UXP Plugin API\
**Tags:** uxp, javascript\
**Created:** [January 26, 2025, 7:54pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127 "2025-01-26T19:54:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [January 26, 2025, 7:54pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/1 "2025-01-26T19:54:00Z")

</div>

No matter how I try to get [`fs` module](https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/fs/) working, for eveyry function I get:

> … is not a function

In Dev Tools console it works just fine with:

```auto
const fs = require("fs")
fs.readdirSync("plugin:/")

```

But same code in the plugin does not - `fs` in the plugin is just empty object `{}`

Do I need something in the manifest? Docs don’t say anything 😕

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [January 26, 2025, 11:19pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/2 "2025-01-26T23:19:12Z")

</div>

This is a plugin that reads text from sample.txt on the desktop and displays it in a Photoshop dialog.

It required permissions of `“localFileSystem”: “fullAccess”`.

```auto
// index.js

const { app } = require('photoshop') ;
const fs = require('fs') ;
const os = require('os') ;

const main = async () => {
  const filepath = path.join(os.homedir(), 'Desktop', 'sample.txt') ;
  const text = fs.readFileSync(filepath, {encoding: 'utf-8'}) ;
  app.showAlert(text) ;
} ;

```

```auto
// manifest.json

"requiredPermissions": {
  "localFileSystem": "fullAccess"
}, 

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [January 27, 2025, 9:29am UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/3 "2025-01-27T09:29:24Z")

</div>

Oh, yes… I have `"localFileSystem": "fullAccess"` too. Still `not a function` 😕

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [January 27, 2025, 10:53am UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/4 "2025-01-27T10:53:41Z")

</div>

Tried readdirSync just to be sure, and it worked.

```auto
const { app } = require('photoshop') ;
const fs = require('fs') ;
const os = require('os') ;

const main = async () => {
  const contents = fs.readdirSync(path.join(os.homedir(), 'Desktop')) ;
  app.showAlert(contents.join('\n')) ;
} ;

```

Were you using manifest v4 until recently? requiredPermissions will be enabled in v5. And I remember that when we migrated from v4 to v5, we had to try many loads until it was applied, or something like that, anyway it finally came to fruition.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [January 27, 2025, 11:05am UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/5 "2025-01-27T11:05:59Z")

</div>

Nope, I’m on v5 for quite some time now ☹  
As I mentioned, in console it works, but not if I run from plugin 😕 I’ll try to do more digging today. Sounds like I’m missing something on my side, but can’t figure out what it is

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [January 27, 2025, 2:25pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/6 "2025-01-27T14:25:22Z")

</div>

So it’s something with packaging the plugin. I found in my Webpack config I have this:

```auto
        resolve: {
            extensions: [".js", ".jsx", ".ts", ".tsx"],
            fallback: {
                "fs": false,
                "tls": false,
                "net": false,
                "zlib": false,
                "http": false,
                "https": false,
                "path": require.resolve("path-browserify"),
                "crypto": require.resolve("crypto-browserify"),
                "buffer": require.resolve("buffer/"),
                "stream": require.resolve("stream-browserify"),
            },
        },

```

If I remove `"fs": false,`, then I get

> Error: Cannot find module ‘fs’

😕

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [January 27, 2025, 2:28pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-use-fs-module/9127/7 "2025-01-27T14:28:34Z")

</div>

Had to add this to Webpack config:

```auto
        externals: {
            fs: "commonjs2 fs",
        },

```

Good thing I already had:

```auto
        externals: {
            uxp: "commonjs2 uxp",
            photoshop: "commonjs2 photoshop",
            os: "commonjs2 os",
        },

```

If not this example, I would’ve pulled my hair out
