"module 'widget' not found"

Hello,

I’m very new to Corona and I’m trying to get a basic application (the flashlight tutorial) to work for iOS. I am getting the following error when I try to run the app (both on a real device and a simulator):

2018-04-13 09:20:40.853912-0700 App[890:325836] ERROR: Runtime error

/Users/useradmin/Desktop/App/ios/…/Corona/main.lua:2: module ‘widget’ not found:

no field package.preload[‘widget’]

no file '/var/containers/Bundle/Application/AE8A8A81-334D-46E8-A733-F873B3C7C00A/App.app/corona-plugins/widget.lua’

no file '/var/containers/Bundle/Application/AE8A8A81-334D-46E8-A733-F873B3C7C00A/App.app/widget.lua’

no file '/var/containers/Bundle/Application/AE8A8A81-334D-46E8-A733-F873B3C7C00A/App.app/widget.lua’

no file '/var/containers/Bundle/Application/AE8A8A81-334D-46E8-A733-F873B3C7C00A/App.app/corona-plugins/widget.so’

no file './widget.so’

no file '/var/containers/Bundle/Application/AE8A8A81-334D-46E8-A733-F873B3C7C00A/App.app/widget.so’

stack traceback:

[C]: in function 'require’

/Users/useradmin/Desktop/App/ios/…/Corona/main.lua:2: in main chunk

I’ve tried including plugin.widget in build.settings as a plugin, but that didn’t work. I redownloaded Corona, thinking something went wrong with my install, but that made no difference. I am not able to find widget in my Mac. I’ve also looked at various forum explanations and rechecked the tutorial for answers. I am able to build this same application on Android just fine with no errors or special changes to get widget to work. Here is the line in question:

local widget = require( “widget” )

I copy pasted this from Corona itself and I see this exact line in many lua files, so I don’t believe there’s anything wrong with the code itself. My Xcode version is 9.3 and I have the latest Corona.

 

 

The widget library isn’t a plugin, so you don’t need to touch build.settings for it.  You should just need to require widget like you are. Are you doing a simulator build or a native build (using Xcode)? 

Rob

I’m using Xcode. I’ve been tinkering with it and noticed that it was able to get past this line if it happened before require “plugin.flashlight”, but it would get hung up on widget_button later on this first line:

local onOffSwitch = widget.newButton(

    {

        x = display.contentCenterX,

        y = display.contentCenterY,

        label = “Turn On”,

        onRelease = handleButtonEvent

    }

)

Please put this at the top (or at least before you try to use the widget.* lib) of the file where you are having the problem:

local widget = require "widget"

I get the exact same behavior. Here is the full file if you’d like to take a closer look:

local flashlight = require “plugin.flashlight”

local widget = require “widget”

 

– This event is dispatched to the global Runtime object by “didLoadMain:” in MyCoronaDelegate.mm

local function delegateListener( event )

native.showAlert(

“Event dispatched from ‘didLoadMain:’”,

"of type: " … tostring( event.name ),

{ “OK” } )

end

Runtime:addEventListener( “delegate”, delegateListener )

 

local function listener( event )

print( “Received event from Flashlight plugin (” … event.name … "): ", event.message )

end

 

local lightState = “off”

 

local function handleButtonEvent( event )

    if ( lightState == “off” ) then

        flashlight.on()

        lightState = “on”

        event.target:setLabel( “Turn Off” )

    else

        flashlight.off()

        lightState = “off”

        event.target:setLabel( “Turn On” )

    end

    return true

end

 

local onOffSwitch = widget.newButton(

    {

        x = display.contentCenterX,

        y = display.contentCenterY,

        label = “Turn On”,

        onRelease = handleButtonEvent

    }

)

 

flashlight.init( listener )

  1. Actually can you zip up your project folder and attach it here, just click that ‘more reply options’ button below the edit area.

attaching_files.jpg

  1. Please format code posts using the features in the forums editor.

formatyourcode.jpg

Here is the attached ZIP of the project. Please let me know if you cannot reproduce the error. It could be an environment issue.

Here.  I took your code and put it in one of my starter projects.

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/04/widgetHelp.zip

I see no issues except that there is no init() function in the flashlight module.

Compare the files in my project to yours.

Your build.settings file is wrong.

Read the docs for flashlight and compare your files to mine.

http://spiralcodestudio.com/plugin-flashlight/

Thank you. I was trying to get the tutorial to work with a user defined library (the tutorial had us put flashlight code in PluginLibrary.mm), but that didn’t seem to work. This got it working though.

well I had the similar problem, glad that i found the solution in your answers.

The widget library isn’t a plugin, so you don’t need to touch build.settings for it.  You should just need to require widget like you are. Are you doing a simulator build or a native build (using Xcode)? 

Rob

I’m using Xcode. I’ve been tinkering with it and noticed that it was able to get past this line if it happened before require “plugin.flashlight”, but it would get hung up on widget_button later on this first line:

local onOffSwitch = widget.newButton(

    {

        x = display.contentCenterX,

        y = display.contentCenterY,

        label = “Turn On”,

        onRelease = handleButtonEvent

    }

)

Please put this at the top (or at least before you try to use the widget.* lib) of the file where you are having the problem:

local widget = require "widget"

I get the exact same behavior. Here is the full file if you’d like to take a closer look:

local flashlight = require “plugin.flashlight”

local widget = require “widget”

 

– This event is dispatched to the global Runtime object by “didLoadMain:” in MyCoronaDelegate.mm

local function delegateListener( event )

native.showAlert(

“Event dispatched from ‘didLoadMain:’”,

"of type: " … tostring( event.name ),

{ “OK” } )

end

Runtime:addEventListener( “delegate”, delegateListener )

 

local function listener( event )

print( “Received event from Flashlight plugin (” … event.name … "): ", event.message )

end

 

local lightState = “off”

 

local function handleButtonEvent( event )

    if ( lightState == “off” ) then

        flashlight.on()

        lightState = “on”

        event.target:setLabel( “Turn Off” )

    else

        flashlight.off()

        lightState = “off”

        event.target:setLabel( “Turn On” )

    end

    return true

end

 

local onOffSwitch = widget.newButton(

    {

        x = display.contentCenterX,

        y = display.contentCenterY,

        label = “Turn On”,

        onRelease = handleButtonEvent

    }

)

 

flashlight.init( listener )

  1. Actually can you zip up your project folder and attach it here, just click that ‘more reply options’ button below the edit area.

attaching_files.jpg

  1. Please format code posts using the features in the forums editor.

formatyourcode.jpg

Here is the attached ZIP of the project. Please let me know if you cannot reproduce the error. It could be an environment issue.

Here.  I took your code and put it in one of my starter projects.

https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/04/widgetHelp.zip

I see no issues except that there is no init() function in the flashlight module.

Compare the files in my project to yours.

Your build.settings file is wrong.

Read the docs for flashlight and compare your files to mine.

http://spiralcodestudio.com/plugin-flashlight/

Thank you. I was trying to get the tutorial to work with a user defined library (the tutorial had us put flashlight code in PluginLibrary.mm), but that didn’t seem to work. This got it working though.