Build Talking Apps for Alexa: Can't find i18next module (page 23)

@habuma
I am running on Windows 11 with VS Code. I make all of the internationalization changes to the code. Then I open the command prompt and enter “npm install --prefix lambda i18next” while in the lambda directory. This creates another “lambda” directory to the current “lambda” directory and when I try to deploy and test the program I get “i18next” module is not found. I remove the sub-directory lambda and run the same npm command from the parent directory and everything looks good but again the i18next module can’t be found by the skill. I can see the folders and code in the lambda/node_modules sub-directory. I gave up and removed the i18next features and hard coded the responses. What did I do wrong?

Long answer follows…I’m thinking out loud here, hoping to arrive at a solution for you…

When you run npm install with --prefix you are giving it a path to where the Node project is located. If you don’t specify the --prefix parameter, it defaults to the current directory.

If you are in the Alexa project’s lambda directory, you don’t need (and shouldn’t use) the --prefix parameter because you are already in the part of the project that is the Node project. It will just add the dependency to the package.json in the current directory.

If you are in the Alexa project’s root, then you must use --prefix or it will try to put it into a package.json file in the current directory. And when it doesn’t find one, it will install it in a node_modules directory at your user’s home directory (which works for some use cases, but not so much when you plan to deploy and run your code somewhere other than your own machine).

So, you can either use --prefix from the Alexa project’s root or not use it if you are already in the lambda directory.

But you said you did it first with --prefix in the lambda directory and that created a new lambda directory. That’s not what you want, of course, but that is what I’d expect to happen. So you deleted that new lambda and did it again from the root (presumably with --prefix). You say that after doing that you see all of the modules in lambda/node_modules, so that all sounds right. May I assume that you see everything listed in lambda/package.json?

If so, then I can’t imagine it not working after you deploy it again. Assuming that you’re doing an Alexa-hosted skill, that means git commit of your changes…if AWS-hosted, then ask deploy.

In the Alexa-hosted case, you might need to give it a minute after the commit for the changes to be picked up. It’s not instantaneous. There’s a CI system that sees the commit changes and then deploys them. All together, I’ve seen it take several minutes on a slow day. One thing I’d do is go into the developer console, go to the “Code” tab, and inspect the package.json and relevant .js files there to see if Alexa has picked them up yet. If not, then wait a bit longer. If they are there, I’d maybe try deploying from the dev console (e.g., push the “Deploy” button at the top right) and waiting for that to complete. Also, note any warnings that might appear at the top of the page of the Code tab. (Note them, but then wait a minute or so and refresh to page to see if they go away on their own.)

If that still doesn’t work, then I’m stumped (well, mostly).

Try that stuff first and if you still have trouble, ping me again. I have some other ideas, but don’t want to make this reply any longer than it already is if the most common things will help you.

Yay! You fixed it!

I ran npm uninstall and from the lambda did the install and deployed it (and waited) and it worked!

Thank you,

Ken Gladden

If you don’t hear back from me in 24 hours call or text (650) 400-7814

Awesome! Glad it works.

Just FYI: I’ve seen cases where even after deploying and waiting, it refuses to deploy. Upon further inspection, I see a warning at the top of the Code tab saying that the endpoint has changed and the code below isn’t being used. But that only happens after I frequently start and stop sessions with ask run to run things locally while I test. I’ve not figured out yet why, but sometimes it sets the endpoint back on its own and sometimes it doesn’t. But there is a link in the warning that you can click to fix that.

I’ve also occasionally seen it get confused/behind on merging changed from the master branch to the dev branch. I’m not sure why this happens, either…it only happens sometimes. But the fix is to force a merge from master to dev (you have to use --no-verify when pushing to force it).

And almost completely unrelated, but I’ve recently learned that the null-safe chaining operator (?.) might work in your local JS code, but doesn’t work in the version of Node that your skill runs in on Lambda. (Super annoying and the error isn’t helpful when that happens…I lost nearly 3 hours on a project this past week trying to figure that one out.)