简体   繁体   中英

Can't access “v8” outside of node.js repl

I needed to use the "v8" variable of node.js to serialize and deserialize some buffers. But I can't seem to access it outside of the Node.js repl. Here are some screenshots

This is accessing v8 inside of the node.js repl

this is trying to access v8 inside of a file

Are there any work arounds or ways I could use to access v8 inside of a file?

v8 , in a REPL, is a pre-defined variable that is the same as the v8 inbuilt module .

You can access the module through ES modules and CommonJS:

// ES
import v8 from "v8";

// CommonJS
const v8 = require("v8");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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