zertosh / v8-compile-cache

Require hook for automatic V8 compile cache persistence
MIT License
722 stars 42 forks source link

question: can the package be used in esm? #41

Open aladdin-add opened 2 years ago

cbratschi commented 1 year ago

Tried it and got: TypeError: Invalid host defined options

BoyYangzai commented 1 year ago

can it be resolved?

robhogan commented 1 year ago

The root of this looks to be the use import() (not necessarily importing ESM) from a VM https://github.com/nodejs/node/issues/35889 - this has been buggy in Node at least until https://github.com/nodejs/node/pull/48510.

At a minimum, it looks like v8-compile-cache needs to implement importModuleDynamically when calling vm.Script but that API looks pretty unstable in recent Node releases, and:

We do not recommend using it in a production environment.

Repro for experimenting with this: https://github.com/robhogan/v8-compile-cache-issue

JulioC commented 1 year ago

At a minimum, it looks like v8-compile-cache needs to implement importModuleDynamically when calling vm.Script but that API looks pretty unstable in recent Node releases, and:

There is an open PR with a fix using importModuleDynamically: https://github.com/zertosh/v8-compile-cache/pull/47

mmmmmmmgo commented 3 months ago

If not, can you support ignoring esm?