I noticed an error while using this package with Node.js v16.13.2 [^1]. Specifically, when not providing a filename myself, I'm seeing the error:
.../node_modules/eval/eval.js:38
var _filename = filename || module.parent.filename;
^
TypeError: Cannot read properties of undefined (reading 'filename')
at module.exports (.../node_modules/eval/eval.js:38:45)
at file:.../test.js:3:1
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
View the test.js script
```js
import jsEval from "eval";
jsEval("module.exports = { };");
```
This seems to me related to the fact that I'm using CommonJS code (namely this package) from ESModules code. Because ESModule doesn't use module, I'm guessing module.parent is undefined and hence the filename cannot be obtained.
The work-around is pretty simple (at least for now): just provide a filename. However, as the filename is optional in the API, I think it would make sense to find an alternative default filename to be used when none is provided - one that works when calling this package from ESModule code.
I noticed an error while using this package with Node.js v16.13.2 [^1]. Specifically, when not providing a
filename
myself, I'm seeing the error:View the test.js script
```js import jsEval from "eval"; jsEval("module.exports = { };"); ```This seems to me related to the fact that I'm using CommonJS code (namely this package) from ESModules code. Because ESModule doesn't use
module
, I'm guessingmodule.parent
isundefined
and hence the filename cannot be obtained.The work-around is pretty simple (at least for now): just provide a
filename
. However, as thefilename
is optional in the API, I think it would make sense to find an alternative defaultfilename
to be used when none is provided - one that works when calling this package from ESModule code.Also, see https://github.com/ericcornelissen/svgo-action/issues/548#issuecomment-1124342245 for more background information on how I encountered this problem.
[^1]: I did not try to figure out the exact version(s) of Node.js where this issue first happens.