Closed helloanoop closed 1 year ago
Its important to note that I am running the script from /Users/anoop/bruno/bruno
folder while attempting to load the external module from another location /Users/anoop/Github/github-rest-api-collection/node_modules/crypto-js
Is this kind of behaviour not supported ?
Found the fix. Closing the issue.
const { NodeVM } = require('vm2');
const script = `
const crypto = require('crypto-js');
`
const vm = new NodeVM({
require: {
external: true,
root: ['/Users/anoop/Github/github-rest-api-collection']
}
});
vm.run(script, '/Users/anoop/Github/github-rest-api-collection/index.js`);
Adding a name even for an embedded script did the job:
const { NodeVM } = require('vm2');
const script = `
const crypto = require('crypto-js');
`
const vm = new NodeVM({
require: {
external: true
}
});
vm.run(script, 'vm2.js`);
Here is my JS
Here is the error I am seeing