Skip to content

Missing Imports using TSX, ellipsis and transpileOnly (ts-loader) #15727

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

Closed
olmobrutall opened this issue May 10, 2017 · 6 comments
Closed

Missing Imports using TSX, ellipsis and transpileOnly (ts-loader) #15727

olmobrutall opened this issue May 10, 2017 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@olmobrutall
Copy link

Hi Roslyn Team,

This is a follow-up of this issue: TypeStrong/ts-loader#538

I'm responsible for a set of Framework / Applications that use TS and React intensively and trying to update to TS 2.3.

We're using webpack, ts-loader and the option transpileOnly that makes the initial compilation much faster (40s -> 150s). transpileOnly will call transpileModule.

Using this transpileOnly, in combination with ellipsis in TSX elements makes TS to forget importing some references.

Github Repository that reproduces the problem in isolation

https://github.com/olmobrutall/tsxError

TS Source

import * as React from 'react'
import { classes } from './Utils'

export interface Typeahead2Props {
    spanAttrs?: React.HTMLAttributes<HTMLSpanElement>;
}

export default class Typeahead2 extends React.Component<Typeahead2Props, {}>
{
    render() {

        return (
            <span {...this.props.spanAttrs} className={classes(this.props.spanAttrs && this.props.spanAttrs.className, "sf-typeahead")}>
              
            </span>
        );
    }
}

JS Full compilation (Right)

Object.defineProperty(exports, "__esModule", { value: true });
var React = __webpack_require__(35);
var Utils_1 = __webpack_require__(36);
var Typeahead2 = (function (_super) {
    __extends(Typeahead2, _super);
    function Typeahead2() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Typeahead2.prototype.render = function () {
        return (React.createElement("span", __assign({}, this.props.spanAttrs, { className: Utils_1.classes(this.props.spanAttrs && this.props.spanAttrs.className, "sf-typeahead") })));
    };
    return Typeahead2;
}(React.Component));
exports.default = Typeahead2;

JS Transpilation (Wrong)

Object.defineProperty(exports, "__esModule", { value: true });
var React = __webpack_require__(35);
var Typeahead2 = (function (_super) {
    __extends(Typeahead2, _super);
    function Typeahead2() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Typeahead2.prototype.render = function () {
        return (React.createElement("span", __assign({}, this.props.spanAttrs, { className: Utils_1.classes(this.props.spanAttrs && this.props.spanAttrs.className, "sf-typeahead") })));
    };
    return Typeahead2;
}(React.Component));
exports.default = Typeahead2;

Note the missing Utils_1

Thanks for the nice work :)

@jquintozamora
Copy link

jquintozamora commented May 10, 2017

Hi @olmobrutall ,
Similar issue happened to me on #15721.

Temporary I used this workaround:
Import with require and different variable name "cardType":

const cardType = require("../ViewerItem/ViewerItemCardType");

Use it using this variable name:
cardType.ViewerItemCardType.Big

Isn't ideal, but worked temporary, let's see if it's provided a quick fix for that, which seems important.

Maybe in your scenario would be like:

Import:
const utils = require("./Utils");

Usage:

<span {...this.props.spanAttrs} className={utils.classes(this.props.spanAttrs && this.props.spanAttrs.className, "sf-typeahead")}>
</span>

@olmobrutall
Copy link
Author

Hi @jquintozamora

Thanks for your detailed answer, indeed looks like the same problem.

Are you also using TS-loader with transpileOnly?

I've found workarounds but then i found another bug...

The issue can also happen with imported symbols inside of the JSX element with ellipsis, not in properties.

It's a set of big applications and is failing at runtime so I'll prefer a proper solution.

Let's see if the sun arrives to Seattle and we get some attention :)

@jquintozamora
Copy link

Hi @olmobrutall , Actually I am using ts-loader, but not transpileOnly.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label May 10, 2017
@olmobrutall
Copy link
Author

Strage, removing transpileOnly fixed the problem in my case...

@mhegazy
Copy link
Contributor

mhegazy commented May 10, 2017

Looks like a duplicate of #15469. should be fixed in typescript@next and in the next TS 2.3.3 release next week.

can you give typescript@next a try and see if you are still running into issues?

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Bug A bug in TypeScript labels May 10, 2017
@olmobrutall
Copy link
Author

Looks like works 👍

@mhegazy mhegazy closed this as completed May 11, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants