Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想提供文件系统访问以用于fs. 如何授予 vm2 进程访问特定目录的权限?
fs
我试过设置external为true和 a rootof /。该进程在 vm2 外部运行时能够访问该目录。
external
true
root
/
你定了builtin: ['fs']吗?
builtin: ['fs']
试试下面的代码示例
const {NodeVM} = require('vm2'); const vm = new NodeVM({ console: 'inherit', sandbox: {}, require: { external: true, builtin: ['fs', 'path'], root: "./", mock: { fs: { readFileSync() { return 'Nice try!'; } } } } });