Search code examples
javascriptmeteor

Meteor import async function to be used in a method call


This Meteor app gives the error TypeError: vinXXX is not a function when trying to call an exported async function saved in a const variable "vinXXX" from within a method call in a sibiling folder which has been imported in the methods follder. Any idea why and how to fix it? Thanks

//imports/api/vehicles/methods.js

import { vinXXX } from './vinXXX.js'
Meteor.methods({
    'extractData': function (plate) {
        console.log('method called: ', plate)
        vinXXX(plate, 'UUU');  // CAR HISTORY
    }
});



//imports/api/vehicles/vinXXX.js

const vinXXX = async (plate, state) => {...}
module.exports = vinXXX;


Solution

  • You are setting the exports to be vinXXX itself, not an object containing it. So your import needs to be for the default:

    import vinXXX from './vinXXX.js'