Bug while importing packages with lazy loading
Deadly0 opened this issue · 9 comments
I have configured webpack and it works well, but when i try to import jagi:astronomy empty object is the result of the import. At the same time i can import reywood:publish-composite and other packages. Example
import astronomy from 'meteor/jagi:astronomy';
import { publishComposite } from 'meteor/reywood:publish-composite';
console.log(astronomy, publishComposite); // print: {} [Function: publishComposite]
Any ideas why it happened and how to fix it
Thx!
How about importing like
import * as astronomy from 'meteor/jagi:astronomy';
@ardatan the same result.
Also import {Class, Enum} from 'meteor/jagi:astronomy';
gives Class
and Enum
=== undefined
Could you share the result of Package['jagi:astronomy']
?
So, it is not undefined and returns empty object. It doesn’t look like related to meteor-webpack; because there is no export in it.
@ardatan Any ideas why it happened? I clearly see export in main Astronomy file
import './core/ejson.js';
import './modules/core/module.js';
import './modules/storage/module.js';
import './modules/behaviors/module.js';
import './modules/events/module.js';
import './modules/methods/module.js';
import './modules/helpers/module.js';
import './modules/fields/module.js';
import './modules/indexes/module.js';
import './modules/validators/module.js';
import Config from './core/config.js';
import Module from './core/module.js';
import Class from './core/class.js';
import reservedKeywords from './core/reserved_keywords.js';
import Enum from './modules/fields/Enum.js';
import Union from './modules/fields/Union.js';
import Type from './modules/fields/type.js';
import Field from './modules/fields/Field';
import ScalarField from './modules/fields/ScalarField';
import ObjectField from './modules/fields/ObjectField';
import ListField from './modules/fields/ListField';
import Behavior from './modules/behaviors/behavior.js';
import Validator from './modules/validators/validator.js';
import Validators from './modules/validators/validators.js';
import { ValidationError } from 'meteor/mdg:validation-error';
import Event from './modules/events/event.js';
const Astro = {
config: Config,
Config,
Module,
Class,
Enum,
Union,
Type,
Field,
ScalarField,
ObjectField,
ListField,
Behavior,
Validator,
Validators,
ValidationError,
Event,
reservedKeywords
};
export {
Astro,
Module,
Class,
Enum,
Union,
Type,
Field,
ScalarField,
ObjectField,
ListField,
Behavior,
Validator,
Validators,
ValidationError,
Event,
reservedKeywords
};
Could you reproduce a repo about this bug?
@ardatan looks like this bug not with jagi:astronomy but with meteor lazy loading. The latest version of jagi:astronomy start using lazy loading. Old version jagi:astronomy@2.5.8 without lazy loading works fine with webpack. I guess this bug affects all packages which use lazy loading.
As a workaround for jagi astronomy I created a local package in ./packages/disable-dynimport
which imports astronomy using Meteor imports and makes all exports available through Packages
global.
This way astronomy is available in webpack as well.
This does mean, that all advantages of lazy loading are gone.
Code:
// ./packages/disable-dynimport/package.js
Package.describe({
name: "disable-dynimport",
summary: "dynimports => static imports",
version: "0.0.1",
});
Package.onUse(function (api, where) {
api.use(['ecmascript', 'jagi:astronomy',]);
api.addFiles(["main.js"]);
});
// packages/disable-dynimport/main.js
import Astro from 'meteor/jagi:astronomy'
Object.keys(Astro).forEach(key => {
Package['jagi:astronomy'][key] = Astro[key]
})
// .meteor/packages
// append "disable-dynimport"
Not a solution, but a working workaround. Better then nothing...
Still it would be great to have a solution which works for all packages and without configuration. Best would be, to keep lazy loading functionality