#can't resolve 'fs' on payload.config file

2 messages · Page 1 of 1 (latest)

wind void
#

trying to load the colllections dynamically by reading all ts files in specific foder liek this:

import fs from 'fs'

const folderPath = path.join(__dirname, 'collections');

const modules = fs.readdirSync(folderPath)
  .filter(file => file.endsWith('.ts'))
  .map(file => {
    const module = require(path.join(folderPath, file)).default;
    const moduleName = path.basename(file, '.ts');
    return { slug: moduleName, ...module };
  });


  console.log(modules)

it seems like the modules printed correctly but after a second i get

on payload.config file i get :


[15:23:15] INFO (payload): Payload Admin URL: http://localhost:3001/admin
webpack built 2817d328106c610ffe2c in 1178ms
WARNING in ./src/payload.config.ts 90:17-53
Critical dependency: the request of a dependency is an expression

ERROR in ./src/payload.config.ts 85:0-20
Module not found: Error: Can't resolve 'fs' in '/Users/guy/proj/contra/src'

webpack compiled with 1 error and 1 warning
fallen needleBOT