3

One error is:

"errorMessage": "Cannot find module './dist/commonjs/index.js'", 

The other error is:

Unable to import module 'index': Error at Function.Module._resolveFilename (module.js:469:15) 

I've seen other posts on the second error, but I've done everything they recommend and still stuck. And they don't mention the /dist/commonjs/index.js issue.

My Lambda Function Handler is set to "index.handler" and my main code is in index.js.

I'm on Windows. My zip file (HebrewVocab.zip) looks like this. enter image description here And the node_modules folder seems to be complete and looks like this: enter image description here I zipped and uploaded with a PowerShell that I wrote:

Compress-Archive -Path index.js,package.json,node_modules -DestinationPath $ZipFileName aws lambda update-function-code --function-name HebrewVocab --zip-file fileb://HebrewVocab.zip 

My index.js starts with this code:

exports.handler = function(event, context, callback) { var alexa = Alexa.handler(event, context, callback); alexa.registerHandlers(handlers); alexa.execute(); }; 

So I seem to meet all the requirements I read on all the other posts of the similar error. I got a HelloWorld project working earlier, but it didn't use the alexa-sdk.

I also did "npm install npm" as one person on Stackoverflow suggested? Is that necessary?

When I "test" in Lamba, as compared to use Alexa voice to test, I see the details:

"errorMessage": "Cannot find module './dist/commonjs/index.js'", 

Should ./dist/commonjs be the standard path prefix? I have even exported the "function" to my hard drive (as a .zip), and it's exactly what I uploaded), and there is definitely an index.js there in the root of the .zip file.

As a wild guess, I discovered that commonjs is a package, so I did an "npm install commonjs --save", rezipped, and re-uploaded, but same exact result.

I later found there is a /node_modules/i18next/dist/commonjs with an index.js, but not sure if that is related or not. I even tried copying that dist/commonjs to my root and under node_modules, but still same error.

It runs fine when I run locally with:

lambda-local -l index.js -h handler -e eventHelloWorld.json 

Screenshot of errorMessage: enter image description here

And last but not least, my package.json looks like this:

{ "name": "HebrewVocab", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "alexa-sdk": "^1.0.18", "commonjs": "0.0.1", "npm": "^5.5.1" }, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" } 

What else can I try? I posted in Amazon support forum, but no answer, so my project is stuck until I get this figured out.

Update 11/07/2017:

Okay, I just made one crazy observation. The .zip created by the above Powershell creates a different size .zip than doing a Windows right-click, "Send to" Compressed Folder. If I compare the two zips using Total Command "Synchronize Directories", all the files and structure are identical in content. Yet the one created from the manual Windows zip works, and the one created by Powershell gives the error reported originally in this thread. The one created by Powershell is slightly smaller 5,019,123 vs 5,032,770. I tried some of the other powershell compression options, but they created much larger files (turning it off yielded about a 30 MB file).

I have entered the twilight zone - any ideas? ​

3 Answers 3

2

For Windows, I ended up using 7-zip as follows (in a Powershell file, so $ZipFileName is a variable defined on a previous line).

& "c:\Program Files\7-Zip\7z.exe" a -r $ZipFileName index.js package.json client_secret.json GoogleCalendarAPI.js node_modules .credentials calendar-nodejs-quickstart.json 
Sign up to request clarification or add additional context in comments.

Comments

1

I ran into the same issue using a PowerShell script to zip and upload code for a lambda function to be called by an Alexa skill. According to issue #2140 in the PowerShell github repo, Compress-Archive produces archives that are incompatible with OS X, and I suspect any Unix derived OS.

I ended up using bash -c 'zip -r filename *' as mentioned here since I already had the linux subsystem for windows installed. I initially tried Compress-7Zip (also mentioned), but it was very slow, to the point that I thought it had hung the first couple of times I tried it.

Comments

0

You can zip the old school way like this:

function ZipFiles( $zipfilename, $sourcedir ) { Add-Type -Assembly System.IO.Compression.FileSystem $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false) } $zipdest = (Get-Item .\ | Select-Object -ExpandProperty FullName) + '\lambda.zip' $zippath = (Get-Item .\lambda | Select-Object -ExpandProperty FullName) ZipFiles $zipdest $zippath 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.