'fs promises fail in pm2
I do a project and use fs/promises, if I run the server with node everithing is OK, but I want to start the project witj pm2 and get an error
{ Error: Cannot find module 'fs/promises'
2|server | at Function.Module._resolveFilename (module.js:547:15)
2|server | at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
2|server | at require (internal/module.js:11:18)
2|server | at Object.<anonymous> (/home/vr_system/filestorage/vr/utils/helper.js:2:18)
2|server | at Module._compile (module.js:652:30)
2|server | at Object.Module._extensions..js (module.js:663:10)
2|server | at Module.load (module.js:565:32)
2|server | at tryModuleLoad (module.js:505:12)
2|server | at Function.Module._load (module.js:497:3)
2|server | at Module.require (module.js:596:17) code: 'MODULE_NOT_FOUND' }
I'm not an expert, but I assumed that pm2 is running projects with their own node_modules, so go to where pm2 is installed
/usr/local/lib/node_modules/pm2
Then, I opened node_modules to look for the fs dir and see what happened, but I found the following dir with the next files:
/usr/local/lib/node_modules/pm2/node_modules/fs.realpath/index.js
/usr/local/lib/node_modules/pm2/node_modules/fs.realpath/LICENSE
/usr/local/lib/node_modules/pm2/node_modules/fs.realpath/old.js
/usr/local/lib/node_modules/pm2/node_modules/fs.realpath/package.json
/usr/local/lib/node_modules/pm2/node_modules/fs.realpath/Readme
The next code is index,js:
module.exports = realpath
realpath.realpath = realpath
realpath.sync = realpathSync
realpath.realpathSync = realpathSync
realpath.monkeypatch = monkeypatch
realpath.unmonkeypatch = unmonkeypatch
var fs = require('fs')
var origRealpath = fs.realpath
var origRealpathSync = fs.realpathSync
var version = process.version
var ok = /^v[0-5]\./.test(version)
var old = require('./old.js')
function newError (er) {
return er && er.syscall === 'realpath' && (
er.code === 'ELOOP' ||
er.code === 'ENOMEM' ||
er.code === 'ENAMETOOLONG'
)
}
function realpath (p, cache, cb) {
if (ok) {
return origRealpath(p, cache, cb)
}
if (typeof cache === 'function') {
cb = cache
cache = null
}
origRealpath(p, cache, function (er, result) {
if (newError(er)) {
old.realpath(p, cache, cb)
} else {
cb(er, result)
}
})
}
function realpathSync (p, cache) {
if (ok) {
return origRealpathSync(p, cache)
}
try {
return origRealpathSync(p, cache)
} catch (er) {
if (newError(er)) {
return old.realpathSync(p, cache)
} else {
throw er
}
}
}
function monkeypatch () {
fs.realpath = realpath
fs.realpathSync = realpathSync
}
function unmonkeypatch () {
fs.realpath = origRealpath
fs.realpathSync = origRealpathSync
}
How Do I need change this to include fs/promises
Or I'm wrong and this isn't the solution
Please help me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
