OpenResty under Windows 10 , an error: modulelib.redisnot found: No field package.preload[‘lib.redis’]
1. Run the Lua program, and report an error: 500 Internal Server Error Openresty/1.19.9.1. as shown in Figure 1
2. Check the nginx log file, morefunresty.dev.chinamcloud.cn.error.log, modulelib.redisNot found: no field package.preload[‘lib.redis’]. as shown in Figure 2
2021/09/22 17:13:14 [error] 39648#39764: *272 lua entry thread aborted: runtime error: E:/wwwroot/msi_main/resty/app/mods/draw/prizes.lua:10: module 'lib.redis' not found:
no field package.preload['lib.redis']
no file './site/lualib/lib\redis.ljbc'
no file './site/lualib/lib\redis/init.ljbc'
no file './lualib/lib\redis.ljbc'
no file './lualib/lib\redis/init.ljbc'
no file './site/lualib/lib\redis.lua'
no file './site/lualib/lib\redis/init.lua'
no file './lualib/lib\redis.lua'
no file './lualib/lib\redis/init.lua'
no file '.\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lua\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lua\lib\redis\init.lua'
no file './site/lualib/lib\redis.so'
no file './lualib/lib\redis.so'
no file '.\lib\redis.dll'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib\redis.so'
no file 'C:\openresty-1.19.9.1-win64\lib\redis.dll'
no file 'C:\openresty-1.19.9.1-win64\loadall.dll'
no file './site/lualib/lib.so'
no file './lualib/lib.so'
no file '.\lib.dll'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib.so'
no file 'C:\openresty-1.19.9.1-win64\lib.dll'
no file 'C:\openresty-1.19.9.1-win64\loadall.dll'
stack traceback:
coroutine 0:
[C]: in function 'require'
E:/wwwroot/msi_main/resty/app/mods/draw/prizes.lua:10: in main chunk, client: 127.0.0.1, server: morefunresty.dev.chinamcloud.cn, request: "GET /lua/api/draw/prizes?act_id=a0535444-283c-481e-9bcd-b0673a28f3ca HTTP/1.1", host: "morefunresty.dev.chinamcloud.cn"
2021/09/22 17:13:16 [error] 39648#39764: *273 lua entry thread aborted: runtime error: E:/wwwroot/msi_main/resty/app/mods/draw/prizes.lua:10: module 'lib.redis' not found:
no field package.preload['lib.redis']
no file './site/lualib/lib\redis.ljbc'
no file './site/lualib/lib\redis/init.ljbc'
no file './lualib/lib\redis.ljbc'
no file './lualib/lib\redis/init.ljbc'
no file './site/lualib/lib\redis.lua'
no file './site/lualib/lib\redis/init.lua'
no file './lualib/lib\redis.lua'
no file './lualib/lib\redis/init.lua'
no file '.\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lua\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lua\lib\redis\init.lua'
no file './site/lualib/lib\redis.so'
no file './lualib/lib\redis.so'
no file '.\lib\redis.dll'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib\redis.so'
no file 'C:\openresty-1.19.9.1-win64\lib\redis.dll'
no file 'C:\openresty-1.19.9.1-win64\loadall.dll'
no file './site/lualib/lib.so'
no file './lualib/lib.so'
no file '.\lib.dll'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib.so'
no file 'C:\openresty-1.19.9.1-win64\lib.dll'
no file 'C:\openresty-1.19.9.1-win64\loadall.dll'
stack traceback:
coroutine 0:
[C]: in function 'require'
E:/wwwroot/msi_main/resty/app/mods/draw/prizes.lua:10: in main chunk, client: 127.0.0.1, server: morefunresty.dev.chinamcloud.cn, request: "GET /lua/api/draw/prizes?act_id=a0535444-283c-481e-9bcd-b0673a28f3ca HTTP/1.1", host: "morefunresty.dev.chinamcloud.cn"
3. Edit the nginx file and add lua_package_path to configure the file addressing path of openresty
# set search paths for pure Lua external libraries (';;' is the default path):
lua_package_path 'E:/wwwroot/msi_main/resty/app/common/lib/?.lua;;';
server {
}
4. After restarting the Nginx server, the same error is still reported. View the nginx log, add a new line: no filee:/wwwroot/msi_main/resty/app/common/lib/lib\redis.lua, confirm that ?.lua is replaced with: lib\redis.lua, automatically add a level to the directory: /lib
2021/09/22 18:47:41 [error] 42716#42404: *304 lua entry thread aborted: runtime error: E:/wwwroot/msi_main/resty/app/mods/draw/prizes.lua:10: module 'lib.redis' not found:
no field package.preload['lib.redis']
no file 'E:/wwwroot/msi_main/resty/app/common/lib/lib\redis.lua'
no file './site/lualib/lib\redis.ljbc'
no file './site/lualib/lib\redis/init.ljbc'
no file './lualib/lib\redis.ljbc'
no file './lualib/lib\redis/init.ljbc'
no file './site/lualib/lib\redis.lua'
no file './site/lualib/lib\redis/init.lua'
no file './lualib/lib\redis.lua'
no file './lualib/lib\redis/init.lua'
no file '.\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lua\lib\redis.lua'
no file 'C:\openresty-1.19.9.1-win64\lua\lib\redis\init.lua'
no file './site/lualib/lib\redis.so'
no file './lualib/lib\redis.so'
no file '.\lib\redis.dll'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib\redis.so'
no file 'C:\openresty-1.19.9.1-win64\lib\redis.dll'
no file 'C:\openresty-1.19.9.1-win64\loadall.dll'
no file './site/lualib/lib.so'
no file './lualib/lib.so'
no file '.\lib.dll'
no file 'C:\openresty-1.19.9.1-win64\lualib\lib.so'
no file 'C:\openresty-1.19.9.1-win64\lib.dll'
no file 'C:\openresty-1.19.9.1-win64\loadall.dll'
stack traceback:
coroutine 0:
[C]: in function 'require'
E:/wwwroot/msi_main/resty/app/mods/draw/prizes.lua:10: in main chunk, client: 127.0.0.1, server: morefunresty.dev.chinamcloud.cn, request: "GET /lua/api/draw/prizes?act_id=a0535444-283c-481e-9bcd-b0673a28f3ca HTTP/1.1", host: "morefunresty.dev.chinamcloud.cn"
5. Edit the nginx file, add lua_package_path, to configure the file addressing path of openresty, and delete: /lib
# set search paths for pure Lua external libraries (';;' is the default path):
lua_package_path 'E:/wwwroot/msi_main/resty/app/common/?.lua;;';
server {
}
6. Run the lua program, no more errors are reported. as shown in Figure 3

![查看 Nginx 日志文件,morefunresty.dev.chinamcloud.cn.error.log,module 'lib.redis' not found:no field package.preload['lib.redis']。](https://www.shuijingwanwq.com/wp-content/uploads/2021/09/2-14.png)
