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 " 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:
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