meteor-webpack icon indicating copy to clipboard operation
meteor-webpack copied to clipboard

Bug while importing packages with lazy loading

Open Deadly0 opened this issue 7 years ago • 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!

Deadly0 avatar Sep 23 '18 15:09 Deadly0

How about importing like

import * as astronomy from 'meteor/jagi:astronomy';

ardatan avatar Sep 25 '18 18:09 ardatan

@ardatan the same result. Also import {Class, Enum} from 'meteor/jagi:astronomy'; gives Class and Enum === undefined

Deadly0 avatar Sep 25 '18 19:09 Deadly0

Could you share the result of Package['jagi:astronomy']?

ardatan avatar Sep 25 '18 21:09 ardatan

@ardatan Package['jagi:astronomy'] === {}

Deadly0 avatar Sep 26 '18 11:09 Deadly0

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 avatar Sep 26 '18 11:09 ardatan

@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
};

Deadly0 avatar Sep 26 '18 11:09 Deadly0

Could you reproduce a repo about this bug?

ardatan avatar Sep 28 '18 10:09 ardatan

@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:[email protected] without lazy loading works fine with webpack. I guess this bug affects all packages which use lazy loading.

Deadly0 avatar Sep 28 '18 12:09 Deadly0

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

jthomaschewski avatar Oct 24 '18 17:10 jthomaschewski