A problem about the path of lua require

My code is running well, Lua modules under path “modules” is running well, but after I add a sub directory named “common” , create a lua file named “test.lua”, and require (“common/test”)


require “utils”
local nk = require(“nakama”)
local test = require(“common/test”)

then get an error that can’t find the file

{“level”:“fatal”,“ts”:“2019-11-28T17:17:14.086Z”,“msg”:“Failed initializing runtime modules”,“error”:“data/modules/PvpBattle.lua:10: module common/test not found:\n\tno field package.preload[‘common/test’]\n\tno cached module ‘common/test’, \nstack traceback:\n\t[G]: in function ‘require’\n\tdata/modules/PvpBattle.lua:10: in main chunk\n\t[G]: ?”, “stacktrace”:“main.main\n\tmain.go:132\nruntime.main\n\truntime/proc.go:203”}

What should I do?

You should use the correct require argument for your directory structure. In Lua you should use:

local test = require("common.test")
1 Like

it works! thanks :+1:!