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

Module build coming out CJS. #1564

Open
Westbrook opened this issue Apr 11, 2019 · 3 comments
Open

Module build coming out CJS. #1564

Westbrook opened this issue Apr 11, 2019 · 3 comments

Comments

@Westbrook
Copy link

Bug report

  • Skate version: 5.2.4
  • Affected browsers (and versions): At the build level

Current behaviour

When attempting to import Element, {html} from '@skatejs/element-lit-html'; in Typescript, the following error is thrown:

semantic error TS2305 Module '"@skatejs/element-lit-html/dist/cjs"' has no exported member 'html'.

Expected behaviour

The addressed file will return imported classes/functions.

Possible correction...

Poked around to see what I could see and it looks like it might have something to do with https://github.com/skatejs/skatejs/blob/master/build/build.ts#L49 being set to es5 output, which means the modules would be mangled for actual module use, but what do I really know?

This seems to be supported by the actual file in /dist/esm having the same content as /dist/cjs, as follows:

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var element_1 = require("@skatejs/element");
var lit_html_1 = require("lit-html");
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    default_1.prototype.renderer = function () {
        return lit_html_1.render(this.render(), this.renderRoot);
    };
    return default_1;
}(element_1.default));
exports.default = default_1;
var lit_html_2 = require("lit-html");
exports.h = lit_html_2.html;
@Westbrook
Copy link
Author

I just tested tsc(path.dirname(w.config.module), w.dir, 'es2015', 'es2015') and it seems to work. The output is now:

import Element from '@skatejs/element';
import { render } from 'lit-html';
export default class extends Element {
    renderer() {
        return render(this.render(), this.renderRoot);
    }
}
export { html as h } from 'lit-html';

More like I'd expect. It is the same output as the ESNext build, which might mean there are other settings to include, but if this is looking closer to what you'd expect to, I'm happy to supply a PR.

@Westbrook
Copy link
Author

There may be a secondary issue or getting TS to point to the file listed in the module property of package.json, but pointing it manually gets this working.

@Westbrook
Copy link
Author

There is one issue, it seems the settings as they are now do output a reference to global.Promise when processing @skatejs/element, which bombs in the browser:

function delay(fn) {
    if (typeof global.Promise === 'function') {
        // @ts-ignore - Promise.resove() indeed does exist.
        global.Promise.resolve().then(fn);
    }
    else {
        setTimeout(fn);
    }
}

This TS things is...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant