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

Dynamic Imports #313

Open
aghasemi opened this issue Mar 18, 2024 · 1 comment
Open

Dynamic Imports #313

aghasemi opened this issue Mar 18, 2024 · 1 comment

Comments

@aghasemi
Copy link

Hello,

it seems imports in general are supported in Javet, but it is not clear whether dynamic imports are as well or not. May I ask please if there is a minimal example using dynamic imports? More specifically, I want to evaluate the following expression:

import('https://cdn.jsdelivr.net/npm/@xenova/transformers').then(({pipeline}) => {
    pipeline('sentiment-analysis').then(pipe => {
        pipe('I detest it!').then(out => {
            console.log(out)
        })
    })

})

, which takes a few seconds to complete and eventually prints a JSON object to the console. However, so far I only get the "not supported" error message.

Regarding normal import, running import { pipeline } from 'https://esm.sh/@xenova/transformers@2.16.0' returns Cannot find package 'https://esm.sh/@xenova/transformers@2.16.0'. Is there something I am missing?

Thanks

@caoccao
Copy link
Owner

caoccao commented Mar 18, 2024

May I know which mode you were using?

Both Node.js and V8 modes don't have the built-in support to importing from arbitrary resource because:

  1. V8 is a pure script engine that doesn't know file system or network.
  2. Javet is designed to be secure by default. Allowing the guest scripts to access storage or network is not secure at all.

I suggest you write your own module resolver to empower the ESM by fetching the resource in the module resolution. Please refer to this doc for details.

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