pkulchenko / fullmoon

Fast and minimalistic Redbean-based Lua web framework in one file.
MIT License
684 stars 30 forks source link

[help] can not load techbench module ? #3

Closed lost22git closed 2 years ago

lost22git commented 2 years ago

Error message

❯ .\redbean-build.com -vvmbag
D2022-06-07T17:39:50.627197:tool/net/redbean.c:5341:redbean-build:8132] (lua) LuaRun("/.init.lua")
E2022-06-07T17:39:50+000145:tool/net/redbean.c:1034:redbean-build:8132] (lua) failed to run lua code: /.init.lua:1: module 'techbench' not found:
        no field package.preload['techbench']
        no file 'E:\scoop\global\apps\lua\current'
        no file 'E:\scoop\global\apps\lua\current'

zip -sf redbean-build.com

Archive contains:
  usr/share/ssl/root/
  usr/share/ssl/root/amazon.pem
  usr/share/ssl/root/certum.pem
  usr/share/ssl/root/comodo.pem
  usr/share/ssl/root/digicert.pem
  usr/share/ssl/root/geotrust.pem
  usr/share/ssl/root/globalsign.pem
  usr/share/ssl/root/godaddy.pem
  usr/share/ssl/root/google.pem
  usr/share/ssl/root/isrg.pem
  usr/share/ssl/root/quovadis.pem
  usr/share/ssl/root/redbean.pem
  usr/share/ssl/root/starfield.pem
  usr/share/ssl/root/verisign.pem
  usr/share/zoneinfo/
  usr/share/zoneinfo/Beijing
  usr/share/zoneinfo/Berlin
  usr/share/zoneinfo/Boulder
  usr/share/zoneinfo/Chicago
  usr/share/zoneinfo/GST
  usr/share/zoneinfo/Honolulu
  usr/share/zoneinfo/Israel
  usr/share/zoneinfo/Japan
  usr/share/zoneinfo/London
  usr/share/zoneinfo/Melbourne
  usr/share/zoneinfo/New_York
  usr/share/zoneinfo/Singapore
  .ape
  help.txt
  .init.lua // ------------------------------------- added
  favicon.ico
  redbean.png
  .lua/
  .lua/fullmoon.lua // -------------------------- added
  .lua/techbench.lua  // ------------------------ added 
Total 35 entries (255284 bytes)

unzip -lc .\redbean-build.com .init.lua

Archive:  ./redbean-build.com
 extracting: .init.lua
require "techbench"  // -------------------- .init.lua content
pkulchenko commented 2 years ago

@lost4git, everything looks correct in your project setup, but for some reason redbean is not looking in any of the /zip/ folders. This is how the same message looks for me:

E2022-06-07T18:38:56+001281:tool/net/redbean.c:1043:cosmobin:13188] (lua) failed to run lua code: /.init.lua:1: module 'techbench' not found:
        no field package.preload['techbench']
        no file '/zip/.lua/techbench.lua'
        no file '/zip/.lua/techbench/init.lua'
        no file '/zip/.lua/techbench.so'
        no file '/zip/.lua/loadall.so'
        no file './techbench.so'
stack traceback:
        [C]: in function 'require'
        /.init.lua:1: in main chunk

Notice that in my case it checks /zip/.lua/techbench.lua, which is where the file is in your case, but in your stacktrace these paths are not listed. Did you build your redbean copy yourself?

lost22git commented 2 years ago

My build script file (powershell)

image

build.ps1

$ErrorActionPreference = "Stop"

$redbeanUri = "https://justine.lol/redbean/redbean-latest.com"
$redbeanPath = "./redbean.com"
$redbeanBuildPath = "./redbean-build.com"
$luaPath = "./.lua"
$initLuaPath = "./.init.lua"

if(Test-Path $redbeanBuildPath)
{
  Remove-Item $redbeanBuildPath
}

"Checking redbean.com whether exists..."
if(-not $(Test-Path $redbeanPath))
{
  "Downloading redbean.com from $redbeanUri to $redbeanPath"
  Invoke-WebRequest -Uri $redbeanUri -OutFile $redbeanPath
}

"Creating ./.lua folder..."
if($(Test-Path $luaPath))
{
  Remove-Item -Recurse $luaPath
}
mkdir $luaPath

"Copying fullmoon.lua to ./.lua folder..."
Copy-Item "./fullmoon.lua" "$luaPath/fullmoon.lua"

"Copying techbench.lua to ./.lua folder..."
Copy-Item "./examples/techbench.lua" "$luaPath/techbench.lua"

"Generating .init.lua..."
Set-Content -Value "require 'techbench'" -Path $initLuaPath

Write-Host "> Whether to package the resources to redbean.com and start readbean.com (Y/N): " -ForegroundColor Yellow -NoNewline 
$toPackage = Read-Host
if(($toPackage -ne "Y") -and ($toPackage -ne "y"))
{
  return
}
"Packaging to redbean.com..."
Copy-Item $redbeanPath $redbeanBuildPath
zip  $redbeanBuildPath "$luaPath/fullmoon.lua" "$luaPath/techbench.lua"
zip $redbeanBuildPath $initLuaPath

"Starting redbean.com..."
. $redbeanBuildPath -vvmbag
pkulchenko commented 2 years ago

I suspect it's the same issue as #2, as you appear to be using redbean 1.5. I'd expect this to be fixed when redbean 2.0 is out (or if you build redbean with any version 1.6+).

pkulchenko commented 2 years ago

@lost4git, can you re-test with the current redbean version: https://justine.lol/redbean/redbean-latest.com? I expect the issue to be resolved.

lost22git commented 2 years ago

@pkulchenko I found that it is already v2.0, but the problem still exists πŸ˜‚

D2022-06-14T00:00:45.102047:tool/net/redbean.c:4922:redbean-build:1084] (lua) LuaRunAsset("/.init.lua")
E2022-06-14T00:00:45+000000:tool/net/redbean.c:1047:redbean-build:1084] (lua) failed to run lua code: /.init.lua:1: module 'techbench' not found:
        no field package.preload['techbench']
        no file '/E/scoop/global/apps/lua/current'  // still try to load module from my local lua home?
        no file '/E/scoop/global/apps/lua/current'
stack traceback:
        [C]: in function 'require'
        /.init.lua:1: in main chunk
lost22git commented 2 years ago

redbean-build.zip

my build script output

imaitland commented 2 years ago

There may be an issue with your build script, try this, (note I use: bash -c './redbean.com -v', because I am using zsh.)

git clone git@github.com:pkulchenko/fullmoon.git \
  && cd fullmoon \
  && curl https://redbean.dev/redbean-latest.com >redbean.com \
  && chmod +x redbean.com \
  && mkdir .lua \
  && cp fullmoon.lua .lua \
  && cp examples/techbench.lua .lua \
  && echo 'require "techbench"' >.init.lua \
  && zip redbean.com .init.lua .lua/fullmoon.lua .lua/techbench.lua \
  && bash -c './redbean.com -v' 

then to confirm working:

curl http://127.0.0.1:8080/json
lost22git commented 2 years ago

@imaitland same problem in WSL πŸ˜‚

image

pkulchenko commented 2 years ago

I can't reproduce this and the script that @imaitland posted works for me.

I don't understand where /E/scoop/global/apps... path is coming from and why there is no /zip/... paths that should be added by default: https://github.com/jart/cosmopolitan/blob/master/tool/net/redbean.c#L5199.

In any case, it doesn't seem like it's a fullmoon issue, as your copy of redbean for some reason doesn't set proper lua paths, so the modules are not loaded. I'm a bit at a loss here. Can you run redbean with --ftrace option and check if LuaStart and GetDefaultLuaPath functions are on the list?

lost22git commented 2 years ago

it works for me now πŸ˜‚

image

lost22git commented 2 years ago

Thanks to @pkulchenko for your patient answer

lost22git commented 2 years ago

Maybe redbean needs to adjust the priority of the lua path

pkulchenko commented 2 years ago

Yes, we'll have to check on that in redbean; thank you for the update!