RESOLVED “Method ‘method-name’ not found [404]” in Meteor

Playing around in Meteor again as I had an idea for a simple web app to build. As a Meteor-novice, I am using the simple-todos tutorial (using Blaze) as an example of how to build a working app. Tonight, I encountered this error when I tried to call a Meteor method:

Error invoking Method 'assets.insert'
error: 404
errorType: "Meteor.Error"
isClientSafe: true
message: "Method 'assets.insert' not found [404]"
reason: "Method 'assets.insert' not found"

The cause of the issue was that the file defining the assets.insert method was not available on the server-side, which explains the 404 error message. Methods in Meteor need to be imported in the main server code as these are intended to run on the server only. I don’t recall the concept of having to import code/modules when I last worked in Meteor two years ago. The adoption of ECMAScript 6 and associated best practices have means that code stored in other files should be explicitly imported in Meteor applications, instead of being globally scoped (which I believe it was before).

To fix this error, I needed to import the method definition on the server.

In server/main.js, I added the following import statement:
import '../imports/api/assets.js';

Now, this method call executes correctly. So the lesson here is ensure all server-side Meteor methods are imported on the server. Troubleshooting this error was confusing, because the code was running on the client. Inserting a simple console.log('Hello world') would print that message in the Javascript console in the browser, along with the error message. But it was not executing on the server because the code could not be found.

Leave a Reply

Your email address will not be published. Required fields are marked *