Basically, you have a combination of ES module import syntax and commonJS export syntax in your code. Meteor allows them to work together through transpilation, but it's important to understand how each one operates to effectively store and retrieve data.
To make the mixed syntaxes function properly, either change your import to use ES module default import syntax or adjust your export to include a named property on the exported object.
For changing the export to include an object with a property for your named import:
//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 };
Regarding changing the import to a default ES Module import:
//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;
You have the option to solely utilize one syntax without mixing them.
For CommonJS default exports:
//imports/api/vehicles/methods.js
const vinXXX = require('./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;
CommonJs named export example:
//imports/api/vehicles/methods.js
const { vinXXX } = require('./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 };
For ES Module default syntax:
//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
export default async (plate, state) => {...}
And finally, for ES Module Named export:
//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
export const vinXXX = async (plate, state) => {...}