holepunchto / bare

Small and modular JavaScript runtime for desktop and mobile

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bare --eval is not able to load modules from relative paths

freeall opened this issue · comments

When running with --eval, modules from relative paths does not seem to load.

This case works:

$ bare --eval "require('bare-path')"

And all of these exits with Uncaught ModuleError: MODULE_NOT_FOUND: Cannot find module '...' imported from 'file:///bare.bundle/bin/bare.js'

$ bare --eval "require('./')"
$ bare --eval "require('./index.js')"
$ bare --eval "require('/Users/freeall/workspace/holepunch/brittle/index.js')"

The issue is that the --eval and --print flags use direct eval():

bare/bin/bare.js

Lines 42 to 52 in 253139d

if (argv.e) {
eval(argv.e)
Bare.exit()
}
if (argv.p) {
console.log(eval(argv.p))
Bare.exit()
}

The require() function is therefore not scoped to the current working directory, but instead to the bin/bare.js bundle. They should use the Module.* APIs instead.