Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does calling os.tmpDir() produce an error on only some machines?

I am a web development student and a friend of mine is as well. Currently we are utilizing the same files provided by the same textbook in the same class. The point of the exercise is to practice with require.js and explore what it can do. Both of us have taken the same steps to ensure that the proper packages are downloaded and that node and npm versions are up to date.

When node index.js is run on my machine, the server begins listening on ::8080 and prints os.tmpDir() is deprecated. Use os.tmpdir() instead. As I am still fairly new, I'm not 100% sure what deprecation actually is, but I know that the app still works.

When node index.js is run on her machine, she receives an error stating os.tmpDir() is not a function. Where I can go to localhost:8080, she cannot.

We have tried uninstalling and reinstalling node (both stable and latest versions), comparing files (which are identical), and comparing package versions. Somehow, it seems that despite there being no differences between what we are working with (aside from our machines), we are experiencing two different results.

Any suggestions?

The error message:

C:\Users\Nereida\Documents\Classes\Summer2020\WEB.215\requirejs\node_modules\mach\lib\utils\makeTemporaryPath.js:4
var TMP_DIR = require("os").tmpDir();
                            ^

TypeError: require(...).tmpDir is not a function
    at Object.<anonymous> (C:\Users\Nereida\Documents\Classes\Summer2020\WEB.215\requirejs\node_modules[4mmach[24m\lib\utils\makeTemporaryPath.js:4:29)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)[39m
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)[39m
    at Module.load (internal/modules/cjs/loader.js:1049:32)[39m
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)[39m
    at Module.require (internal/modules/cjs/loader.js:1089:19)[39m
    at require (internal/modules/cjs/helpers.js:73:18)[39m
    at Object.<anonymous> (C:\Users\Nereida\Documents\Classes\Summer2020\WEB.215\requirejs\node_modules[4mmach[24m\lib\utils\saveToDisk.js:6:25)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)[39m
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
like image 430
TillyPiddle Avatar asked Mar 03 '23 09:03

TillyPiddle


2 Answers

The answer comes as a comment from djfdev:

There's your problem, she needs to use os.tmpdir() with a lowercase d. As you pointed out, there was a deprecation warning about using the version with the uppercase D. It looks like this was removed entirely in node 14.

So simple... so much time. You are my savior djfdev!

like image 95
TillyPiddle Avatar answered Mar 05 '23 17:03

TillyPiddle


you can fix this problem if you use node > 12

pin your project to use node <= 12 with nvm

echo 'lts/erbium' > .nvmrc nvm use

ref: https://github.com/nvm-sh/nvm/blob/master/README.md

like image 20
Al Joslin Avatar answered Mar 05 '23 19:03

Al Joslin