Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graaljs inside JVM dynamicImport import() broken CJS interop. #339

Closed
frank-dspeed opened this issue Sep 3, 2020 · 3 comments
Closed

graaljs inside JVM dynamicImport import() broken CJS interop. #339

frank-dspeed opened this issue Sep 3, 2020 · 3 comments
Assignees

Comments

@frank-dspeed
Copy link
Contributor

frank-dspeed commented Sep 3, 2020

graaljs inside JVM dynamic import broken interop

ESM & CJS can not dynamic import additional CJS modules inside it also accessing module object inside cjs breaks graalvm silent when loaded via dynamic import inside ESM

JS can also not dynamic import CJS same behavior!

Reproduce able example

module.js

module.exports = { str: 'myString'}
// When the following line gets uncommented the secund console log will not get called silent fails when this file gets imported via dynamic import() no matter if from CJS or ESM
//console.log('ctx',module)
console.log('The Import works correct as this sideEffect gets executed')

index.mjs

//then does not even get called sideEffects do execute
import('./module.js').then(function(x) { console.log('t',x)}) // then does not get called { default: { str: 'myString'}}
export const esm = 'Works' 

index.js

// Will not work
//then does not even get called sideEffects do execute
import('./module.js').then(function(x) { console.log('t',x)}) // then does not get called { default: { str: 'myString'}}

//This will work 
console.log(require('module.js'))
import('./index.esm.js').then(function ({esm}) { console.log(esm) })

Conclusion

dynamicImport import() at present only supports ESM no matter if used in ESM context or CJS
i think also that the current dynamic import implementation does not hornor .mjs === ESM and .cjs === commonjs(require,module)

@eleinadani eleinadani self-assigned this Sep 3, 2020
@frank-dspeed
Copy link
Contributor Author

a little extra info maybe related if we would add into module.js

console.log('ctx',module) // befor the console.log('sideEffect')

it will silent fail all other instructions that come after that and so will not execute the secund console call any access to module when loaded via dynamic import makes graal simply fail silent while it would all work with require from cjs

@eleinadani
Copy link
Contributor

Thanks @frank-dspeed, we'll have a look

@frank-dspeed frank-dspeed changed the title graaljs inside JVM dynamic import broken interop. graaljs inside JVM dynamic import broken CJS interop. Sep 3, 2020
@frank-dspeed frank-dspeed changed the title graaljs inside JVM dynamic import broken CJS interop. graaljs inside JVM dynamicImport import() broken CJS interop. Sep 3, 2020
@frank-dspeed
Copy link
Contributor Author

Solved sorry for creating that issue it is related to a other project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants