njs: Segmentation fault when accessing variables outside in a module.
Hi, @xeioex
- segmentation fault when accessing variables outside in a module.
 
test.js
var a = 1
import foo from "foo.js"
foo.js
export default a
- 
I wonder if a module can access global variables outside? if not, is it possible to access global variables in modules?
 - 
what’s the
globalonly introduced in njs for? 
Thanks.
About this issue
- Original URL
 - State: closed
 - Created 3 years ago
 - Comments: 25 (25 by maintainers)
 
Hi @drsm,
Thanks for your valuable feedback.
Take a look at the second iteration.
Cyclic imports, relative paths, and export default sinking was fixed.
Hi @hongzhidao,
FYI, import binding are not automatically become
globalThisproperties (as it is in Node.js).@xeioex
It looks like cyclic imports are not supported:
BTW,
Hi @hongzhidao, @drsm
Take a look at the patch. The patch adds the support of custom module loader callbacks.
The module_loader is called with
vm,vm->externalandmodulename as arguments.The default loader is here.
@hongzhidao
Hi!
Yes. Anything defined in global scope will be a property of the
globalThisobject.https://github.com/nginx/njs/issues/300#issuecomment-612049416
In such case
ais not a global, because module scopes are independent. And thisshould not compile, because there is no
adefined in module ‘foo.js’