简体   繁体   English

如何在 Nodejs VM 中提供源映射

[英]How to provide source map in Nodejs VM

I am evaluating javascript bundled source code in nodejs using the below code我正在使用以下代码评估nodejs中的javascript捆绑源代码

const javascriptCode = "..."
const javascriptSourceMap = "..."
const wrapper = NativeModule.wrap(javascriptCode);
const script = new vm.Script(wrapper, {
    displayErrors: true
});
script.runInNewContext();

When there is an error in the source code I get errors like this because no source maps are provided当源代码中有错误时,我会收到这样的错误,因为没有提供源映射

ReferenceError: a is not defined
    at VueComponent.testSomething (evalmachine.<anonymous>:43112:7)
    at VueComponent.testSomethingAgain (evalmachine.<anonymous>:43109:12

How to provide source maps to VM so that I can get proper filenames instead of evalmachine.<anonymous> ?如何向 VM 提供源映射,以便我可以获得正确的文件名而不是evalmachine.<anonymous>

Thanks in advance提前致谢

try尝试

require('vm').runInThisContext('console.log(2);\ninvalidJsHere ?= 1;', 'foobar.js');

then you get然后你得到

foobar.js:2
invalidJsHere ?= 1;
               ^

SyntaxError: Unexpected token =
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM