v8-compile-cache
v8-compile-cache copied to clipboard
fix: add tests and better error for dynamic imports
Reference: #30
- Add failing test for dynamic imports
- Add a more relevant error for dynamic imports
In order to support dynamic imports and implement importModuleDynamically
, we have to use vm.SourceModuleText which is still experimental and only available behind --experimental-vm-modules
flag. Yet current situation might be super confusing especially when users are not directly using v8-compile-cache
and see a clueless error like this:
(node:8373) UnhandledPromiseRejectionWarning: TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified.
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:34:9)
After this PR: (git.io link redirects to #30)
(node:8503) UnhandledPromiseRejectionWarning: Error: [v8-compile-cache] Dynamic imports are currently not supported. See https://git.io/Jge6z for more information.
at importModuleDynamically (./home/pooya/Code/v8-compile-cache/v8-compile-cache.js:248:15)
I would be happy to also help in the future with the actual implementation of the VM cache 😊
I wish this PR could be merged, I've spent a week trying to figure out why loading ESM modules dynamically didn't work... this would have saved me so many hours !
/cc @zertosh I know you are probably super busy just pining to see if there is a chance this can be rolled out sometime soon 💚