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

Import module in CLI #167

Closed
LukeSkyw opened this issue Feb 16, 2023 · 2 comments
Closed

Import module in CLI #167

LukeSkyw opened this issue Feb 16, 2023 · 2 comments

Comments

@LukeSkyw
Copy link

Trying to start the CLI with some imported module. For example, trying to load quickjs-require. This is what I tried so far:

bash $ curl -sOL https://raw.githubusercontent.com/IvanGaravito/quickjs-require/master/require.js
bash $ ./qjs --interactive --std --module require.js
QuickJS - Type "\h" for help
qjs > require
ReferenceError: 'require' is not defined
    at <eval> (<evalScript>)
qjs > ctrl^d
bash $ ./qjs --interactive --std --script require.js
SyntaxError: expecting '('
    at require.js:1

bash $ ./qjs --interactive --std -I require.js
QuickJS - Type "\h" for help
qjs > require
ReferenceError: 'require' is not defined
    at <eval> (<evalScript>)
qjs > ctrl^d
bash $ ./qjs
QuickJS - Type "\h" for help
qjs > import { require } from '../require.js'
SyntaxError: expecting '('
    at <evalScript>:1
qjs > 
bash $

I am obviously a little confused as what can be done with the CLI and how but any guidance is appreciated.

I found a way to load it once the CLI is started:

QuickJS - Type "\h" for help
qjs > import('require.js').then(require => this.require = require)
{  }
qjs > require
{ require: function require() }
@LukeSkyw
Copy link
Author

I found a way to "preload" modules but that's not so elegant:

bash $ cat > test.js
import('require.js').then(require => this.require = require);
bash $ ./qjs --interactive --script test.js
QuickJS - Type "\h" for help
qjs > require
{ require: function require() }

@bellard
Copy link
Owner

bellard commented Dec 13, 2023

The CLI is not really adapted to use modules. You should use a script to test the require.js module.

@bellard bellard closed this as completed Dec 13, 2023
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