本地Node版本为v12.18.3,根据Node官方文档说明, fs.readFileSync(path, endcoding)方法,不传encoding时方法返回的是二进制buffer,126行 vm.run(code) vm运行时会报错。
If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
根据vm2官方文档说明,没有找到 vm.runInContext()方法, 160 行运行报错。
What is the difference between Node's vm and vm2?
const vm = require('vm');
vm.runInNewContext('this.constructor.constructor("return process")().exit()');
const {VM} = require('vm2');
new VM().run('this.constructor.constructor("return process")().exit()');
If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.