Open derekvincent opened 4 years ago
same error here, any solutions?
@marcosfede as a temporary solution; I switched to node 8 with command n 8
and worked (see n repo)
This is caused by a deprecation of tmpDir in node. You can read more about it here: https://stackoverflow.com/questions/40913034/
My solution was to do the following:
const Os = require('os');
Os.tmpDir = Os.tmpdir;
Works perfectly, but I just have to remember to do this everytime I npm install
@aelzeiny Could you update the dependencies to use @hapi/hapi
, since hapi
is now deprecated
. Having to use serverless-offline
instead of serverless-offline-python
until this gets resolved 🤷
👍 I am having the same issue, need to update hapi
@DiogoTheCoder Sorry, I'm not a maintainer of this code-base, and I only used it once for a side-project when I ran into this issue. If I were the one to make the change I'll probably break something else. I just thought my comment would be helpful.
This is caused by a deprecation of tmpDir in node. You can read more about it here: https://stackoverflow.com/questions/40913034/
My solution was to do the following:
- open /broadcaster/node_modules/hapi/lib/defaults.js
- Go to line 5 right where it says
const Os = require('os');
- Add line
Os.tmpDir = Os.tmpdir;
Works perfectly, but I just have to remember to do this everytime I npm install
Yep, me too.
In some caes Windows 10 uses tmpDir ( with camel case ) so you can solve this issue like this
var isWin = process.platform === "win32"; var isLinux = process.platform === "linux"; var os = require('os');
if(isWin){ os.tmpDir = os.tmpDir; } else if (isLinux) { os.tmpDir = os.tmpdir; }
this will only be a problem if you use node > 12
pin your project to use node <= 12 with nvm
echo 'lts/erbium' > .nvmrc nvm use
this will only be a problem if you use node > 12
pin your project to use node <= 12 with nvm
echo 'lts/erbium' > .nvmrc nvm use
NodeJS 10 support will be ending very soon.
'NodeJS 10 support will be ending very soon'
very true
'lts/erbium' is Node 12 and good for a little longer
The serverless framework has issues & PRs referring to os.tmpDir so it shouldn't be a problem much longer
This may be helpful for anyone that stumbles across this in the future. An automated version of @ananunaki 's solution:
(I have only tested on Darwin)
// fix-sls-offline.js
const fs = require('fs');
const LINE_NUMBER = 6;
const FILE_LOCATION = 'node_modules/hapi/lib/defaults.js'
const INJECT_FIX_STRING = `
var isWin = process.platform === "win32";
var isLinux = process.platform === "linux";
var isDarwin = process.platform === "darwin";
if (isDarwin || isLinux) {
Os.tmpDir = Os.tmpdir;
} else if (isWin) {
Os.tmpDir = os.tmpDir;
}
`
let data = fs.readFileSync(FILE_LOCATION)
if (data.includes(INJECT_FIX_STRING)) {
console.log("Skipping fix injection, already exists.")
} else {
data = data.toString().split("\n");
data.splice(LINE_NUMBER, 0, INJECT_FIX_STRING);
let text = data.join("\n");
fs.writeFile(FILE_LOCATION, text, (err) => {
if (err) {
return console.log(err);
} else {
return console.log('Injected fix successfully')
}
});
}
// package.json
"scripts": {
"deploy": "serverless deploy",
"start": "serverless offline start",
"prestart": "node fix-sls-offline.js"
}
adding Os.tmpDir = Os.tmpdir;
fixed the issue
I am having trouble with this and hoping someone could help me out. I have downgraded to node 12 but i am still have the same proplem. I tried to locate the "hapi/lib" file but there is no "lib" file. Any ideas?
adding
Os.tmpDir = Os.tmpdir;
fixed the issue
where you add this?
question
This is caused by a deprecation of tmpDir in node. You can read more about it here: https://stackoverflow.com/questions/40913034/
My solution was to do the following:
- open /node_modules/hapi/lib/defaults.js
- Go to line 5 right where it says
const Os = require('os');
- Add line
Os.tmpDir = Os.tmpdir;
Works perfectly, but I just have to remember to do this everytime I npm install
Should I add this as a new line 6 (did not work for me) or on line 5 next to the const Os = require('os');
?
line 5: const Os = require('os'); Os.tmpDir = Os.tmpdir;
or line 5: const Os = require('os');
line 6 : Os.tmpDir = Os.tmpdir;
which way you did it?
@Aiperikurenkeeva both ways should work. Probably a bit cleaner to add Os.tmpDir = Os.tmpdir;
to line 6.
This may be helpful for anyone that stumbles across this in the future. An automated version of @ananunaki 's solution:
(I have only tested on Darwin)
// fix-sls-offline.js const fs = require('fs'); const LINE_NUMBER = 6; const FILE_LOCATION = 'node_modules/hapi/lib/defaults.js' const INJECT_FIX_STRING = ` var isWin = process.platform === "win32"; var isLinux = process.platform === "linux"; var isDarwin = process.platform === "darwin"; if (isDarwin || isLinux) { Os.tmpDir = Os.tmpdir; } else if (isWin) { Os.tmpDir = os.tmpDir; } ` let data = fs.readFileSync(FILE_LOCATION) if (data.includes(INJECT_FIX_STRING)) { console.log("Skipping fix injection, already exists.") } else { data = data.toString().split("\n"); data.splice(LINE_NUMBER, 0, INJECT_FIX_STRING); let text = data.join("\n"); fs.writeFile(FILE_LOCATION, text, (err) => { if (err) { return console.log(err); } else { return console.log('Injected fix successfully') } }); }
// package.json "scripts": { "deploy": "serverless deploy", "start": "serverless offline start", "prestart": "node fix-sls-offline.js" }
Worked like a charm. Thank you very much :)
I am using a fresh serverless install (via brew) and when I enable the serverless-offline-python any sls function I try, produces the error below. If I comment the plugin out in the serverless.yml then everything works again (well not testing my Python-based lambda offline).
MacOS: 10.15.3 Node Version: 14.0.0 Framework Version: 1.68.0 Plugin Version: 3.6.6 SDK Version: 2.3.0 Components Version: 2.30.1