sindresorhus / clear-module

Clear a module from the cache
MIT License
182 stars 25 forks source link

(node:1550) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object #3

Closed tosbaha closed 5 years ago

tosbaha commented 6 years ago

I am trying to remove the cache for mocha test. When I run the below code I get the error

(node:1550) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object

const glob = require('glob-promise');
const clearModule = require('clear-module');

const specs = await glob('./testfiles/*.js', { absolute: true });
console.log(specs);
specs.map(spec => {
  clearModule(spec);
  mocha.addFile(spec);
});

I checked more to find the error and found out that when I use following code

console.log(callerPath());

I get null. So it seems callerPath can't get the folder. I tested above code with NodeJS v10.4.1

thetutlage commented 5 years ago

Ditto, I have the same issue with Node 10.

sindresorhus commented 5 years ago

https://github.com/sindresorhus/clear-module/releases/tag/v3.1.0 should fix this. Let me know if it does not.