用require引用报错,不知道是哪里配置有问题

138 views
Skip to first unread message

wha...@126.com

unread,
Mar 27, 2015, 3:36:19 AM3/27/15
to open...@googlegroups.com
nginx报错如下

2015/03/27 15:24:44 [error] 7494#0: *280 lua entry thread aborted: runtime error: /usr/local/share/lua/5.1/xlsxwriter/workbook.lua:8: variable 'require' is not declared


nginx.conf
location = '/hello' {
  content_by_lua_file html/hello/hello.lua;
}


hello.lua
local Workbook = require "xlsxwriter.workbook"


smallfish

unread,
Mar 27, 2015, 3:45:32 AM3/27/15
to open...@googlegroups.com
xlsxwriter/workbook.lua:8: variable 'require' is not declared

看这个


--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

Yichun Zhang (agentzh)

unread,
Mar 27, 2015, 3:19:33 PM3/27/15
to openresty
Hello!

On Fri, Mar 27, 2015 at 12:36 AM, <wha...@126.com> wrote:
> nginx报错如下
>
> 2015/03/27 15:24:44 [error] 7494#0: *280 lua entry thread aborted: runtime
> error: /usr/local/share/lua/5.1/xlsxwriter/workbook.lua:8: variable
> 'require' is not declared
>

这个错误一般是你错误地使用了module() 函数定义模块所导致的关于名字空间的问题。一般应尽量避免使用 module() 来定义 Lua
模块,而应使用下面的形式:

local _M = {}
function _M.foo() ... end
function _M.bar() ... end
function _M.baz() ... end
return _M

>
> hello.lua
> local Workbook = require "xlsxwriter.workbook"
>

你 100% 确定能复现问题的 hello.lua 文件里真的只有这么一行代码吗?

Regards,
-agentzh

Yichun Zhang (agentzh)

unread,
Mar 27, 2015, 3:21:28 PM3/27/15
to openresty
Hello!

2015-03-27 12:19 GMT-07:00 Yichun Zhang (agentzh):
>> hello.lua
>> local Workbook = require "xlsxwriter.workbook"
>>
>
> 你 100% 确定能复现问题的 hello.lua 文件里真的只有这么一行代码吗?
>

OK,请忽略我这个问题。因为错误并不是 hello.lua 抛出的,而是你的 xlsxwriter.workbook 这个模块里。应当是这个
Lua 模块错误地使用了 module() 函数。由于你没有提供这个库的 Lua 代码,我也无法提供更具体的诊断了。

Regards,
-agentzh

wha...@126.com

unread,
Mar 30, 2015, 2:43:59 AM3/30/15
to open...@googlegroups.com
xlsxwriter.workbook代码太多了,这个是这个文件的地址
https://github.com/jmcnamara/xlsxwriter.lua/blob/master/xlsxwriter/workbook.lua

在 2015年3月28日星期六 UTC+8上午3:21:28,agentzh写道:

wha...@126.com

unread,
Mar 30, 2015, 2:51:49 AM3/30/15
to open...@googlegroups.com
我在机器上使用lua和luajit的命令行,引用xlsxwriter.workbook没有报错,所以我感觉是openresty配置错了

在 2015年3月30日星期一 UTC+8下午2:43:59,wha...@126.com写道:

wha...@126.com

unread,
Mar 30, 2015, 5:06:09 AM3/30/15
to open...@googlegroups.com
我把https://github.com/jmcnamara/xlsxwriter.lua/blob/master/xlsxwriter/strict.lua这个文件的最后一个函数注释掉后,程序能够正常运行,不知道为什么会出现这个问题

在 2015年3月30日星期一 UTC+8下午2:51:49,wha...@126.com写道:

Yichun Zhang (agentzh)

unread,
Mar 30, 2015, 5:22:12 PM3/30/15
to openresty
Hello!

2015-03-29 23:51 GMT-07:00 <wha...@126.com>:
> 我在机器上使用lua和luajit的命令行,引用xlsxwriter.workbook没有报错,所以我感觉是openresty配置错了
>

不是 openresty 配置错了,而是 openresty 的配置更容易暴露出第三方 Lua 库模块中对 Lua API 的错误用法,见

https://github.com/openresty/lua-nginx-module#lua-variable-scope

Regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages