You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vmThreads CommonJS this isn't bound to module.exports #11501
We hit this loading FlexSearch in vmThreads and narrowed it down to how the VM loader calls CommonJS modules. Top-level this isn't bound to module.exports, as it is in Node. In a strict-mode module, it's undefined.
import{expect,test}from'vitest';importcommonjsfrom'commonjs-this-fixture';test('binds CommonJS top-level this to exports',()=>{expect(commonjs).toEqual({value: 42,isExports: true});});
This passes in Node and with --pool=threads. With either --pool=vmThreads or --pool=vmForks, it fails during import:
TypeError: Cannot set properties of undefined (setting 'value')
I'd expect it to pass in all three pools.
CommonjsExecutor._compile calls the wrapper without a receiver. Binding it to this.exports makes the test pass in both VM pools:
Activity