Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug while importing packages with lazy loading #40

Open
Deadly0 opened this issue Sep 23, 2018 · 9 comments
Open

Bug while importing packages with lazy loading #40

Deadly0 opened this issue Sep 23, 2018 · 9 comments
Labels
bug Something isn't working help wanted Extra attention is needed in progress

Comments

@Deadly0
Copy link
Contributor

Deadly0 commented Sep 23, 2018

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!

@ardatan
Copy link
Owner

ardatan commented Sep 25, 2018

How about importing like

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

@Deadly0
Copy link
Contributor Author

Deadly0 commented Sep 25, 2018

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

@ardatan
Copy link
Owner

ardatan commented Sep 25, 2018

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

@Deadly0
Copy link
Contributor Author

Deadly0 commented Sep 26, 2018

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

@ardatan
Copy link
Owner

ardatan commented Sep 26, 2018

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.

@Deadly0
Copy link
Contributor Author

Deadly0 commented Sep 26, 2018

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

@ardatan
Copy link
Owner

ardatan commented Sep 28, 2018

Could you reproduce a repo about this bug?

@Deadly0
Copy link
Contributor Author

Deadly0 commented Sep 28, 2018

@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.

@Deadly0 Deadly0 changed the title Bug while importing jagi:astronomy package Bug while importing packages with lazy loading Sep 28, 2018
@ardatan ardatan added bug Something isn't working help wanted Extra attention is needed in progress labels Oct 13, 2018
@jthomaschewski
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed in progress
Projects
None yet
Development

No branches or pull requests

3 participants