Hi,
i have an application ( Meteor 1.7.0. 4 ) with packages structure like this :
The idea is to to separate mobile and web code when creating bundles. Both of them are declared with lazy: true
web
api.mainModule('client/index.js', 'web.browser', { lazy: true });
mobile
api.mainModule('client/index.js', 'web.cordova', { lazy: true });
In the api package, i am defining ValidatedMethods that import modules from server ( following Meteor Guide ) like this :
export const aMethod = new ValidatedMethod({
name: 'name',
validate: SomeSchema.validator(),
async run({ param1, param2 }) {
if (Meteor.isServer) {
const { functionFromServerModule: method } = await import('../../server/moduleWithFunction');
return method.call(this, { param1, param1 });
}
}
});
For web package everything is OK on browser, i can import methods and call them.
But for mobile, i have error while loading the application in device ( build is OK )
Uncaught SyntaxError: Unexpected token {
Uncaught Error: Cannot find package "xxxxx:api". Try "meteor add xxxxx:api".
When i check with Chrome device inspector, i see that api module contains code from server module ( which is not normal ) that is not transpiled.
...
// node_modules/meteor/xxxxx_api/server/server/moduleWithFunction.js
import { SomeCollection } from '../../modules/some-collection';
...
web package uses methods with same definition but server code was not in xxxxx:api script.
To debug, tried to delete this import :
const { functionFromServerModule: method } = await import('../../server/moduleWithFunction');
return method.call(this, { param1, param1 });
moduleWithFunction code now disappeared from xxxxx:api script and application loads correctly( even if it’s not functional )
I am not sure if’s problem with 1.7.0.4 or dynamic-import from cordova code or maybe babel.
Any idea ?