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

Failure exporting imported sub-modules #430

Closed
brianmhunt opened this issue Jan 6, 2016 · 6 comments
Closed

Failure exporting imported sub-modules #430

brianmhunt opened this issue Jan 6, 2016 · 6 comments

Comments

@brianmhunt
Copy link
Contributor

Minimal Working Example

tl;dr A minimal example exhibiting the problem is:

entry.js

import * as pkg from './package.js'
export {pkg}

package.js

import * as sub from './sub.js'
export {sub}

sub.js

export var wink = 10

Running rollup entry.js gives:

var wink = 10

var pkg = Object.freeze({
    sub: null
});

export { pkg };⏎

Where pkg.sub should be Object.freeze({wink: wink})

Running rollup package.js works as expected.

For some more context, see below.


In the package tko.utils, I have the following code:

spec/utilsDomBehaviors.js

import * as utils from '../index.js'
// ...

index.js

import './src/bind-shim.js'
export * from './src/array.js'
// ...
import * as virtualElements from './src/dom/virtualElements.js'
import * as domData from './src/dom/data.js'

export {virtualElements, domData}

This compiles as-expected when running rollup index.js (or the equivalent gulp task, gulp make).

However, a problem exhibits when I run, from the project root (or from the spec directory, with the entry changed accordingly):

> rollup({ entry: 'spec/utilsDomBehaviors.js' }).then((b) => global.bundle = b)
> console.log(bundle.generate({ format: 'es6' }).code)
// ... Code!

The shim imports fine, and the the array imports/exports as expected.

However, resulting code does not contain either virtualElements or domData. One would expect it to be an Object.freeze....

The objects are referenced in the export part as:

var utils = Object.freeze({
  virtualElements: null,
  domData: null$1,
  // ...
  }

The problem also occurs when using bundle.write, and regardless of the output format.

This issue prevents the easy use of the karma-rollup-preprocessor plugin.

@brianmhunt brianmhunt changed the title Failure resolving imported modules Failure exporting imported sub-modules Jan 6, 2016
brianmhunt added a commit to knockout/tko.utils that referenced this issue Jan 6, 2016
Tests still failing; depends on rollup/rollup#430
brianmhunt added a commit to brianmhunt/rollup that referenced this issue Jan 6, 2016
Rich-Harris added a commit that referenced this issue Jan 9, 2016
Chained namespace imports
@Rich-Harris
Copy link
Contributor

Fixed in 0.24.1 – thanks

@brianmhunt
Copy link
Contributor Author

🍻

@christopherthielen
Copy link
Contributor

I think this is still a problem in 0.25.4:

Link to minimal reproduction http://bit.ly/1UpzaOC

If this is a different problem, please yell at me and I'll open a new issue.

index.js:
export * from "./core"
core.js:
import * as common from "./common"; export { common };
common.js:
export const foo = "foo";

generates (globals):

(function (exports) {
    'use strict';

    const foo = "bar"

    exports.common = null;

}((this.myBundle = this.myBundle || {})));

@brianmhunt
Copy link
Contributor Author

@tyler-johnson
Copy link

tyler-johnson commented Jul 13, 2016

Since this is still an issue as of 0.34, here is a temporary workaround for anyone who was caught by this like I was:

main.js:
export * from "./middle.js";
middle.js:
import * as _foo from "./foo.js"; export const foo = _foo;
foo.js:
export const foo = "bar";

Online Version

@Rich-Harris
Copy link
Contributor

As far as I can tell this is fixed in recent versions – I remember us fixing something similar, so that all makes sense. Will close this (again! 😀 )

brianmhunt added a commit to knockout/tko that referenced this issue May 8, 2017
Tests still failing; depends on rollup/rollup#430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants