Sunday, 28 March 2021

path.join in require statement

I try to use Path.join in require statement like this:

import Path from 'path'

const assetPath = Path.join(process.cwd(), `./lib/asset-manifest.json`)

console.log(assetPath)
'/home/dev/Website/lib/asset-manifest.json'

console.log(
  assetPath === '/home/dev/Website/lib/asset-manifest.json'
)
true

const assets = require(assetPath)

But that throws error that:

Error: Cannot find module '/home/dev/Website/lib/asset-manifest.json'

Though the file is there and require works if I put the string manually in it:

const assets = require('/home/dev/Website/lib/asset-manifest.json')

So I wonder why does not Path.join works in require ?

Best regards



from path.join in require statement

No comments:

Post a Comment