question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage of ... and lodash makes typescript output js file without import and causes undefined error

See original GitHub issue

Get this repository: https://github.com/bhouser/jestReactMockTsx

In typescript subdirectory, do:

npm install --save-dev lodash @types/lodash

Replace ParentComponent.tsx with this content:

import * as React from 'react';
import ChildComponent from './ChildComponent';

import * as _ from 'lodash';

function x() {
    return { ..._.isNil };
}

export default function ParentComponent() {
    return (
        <div
            { ...x() }
        >
            <div className="parentComponent">
                <ChildComponent />;
            </div>
        </div>
    );
}

You will see that usage of { ..._.isNil } makes the transformed source to omit the require for ChildComponent.

When you compile the project with tsc, it does it correctly.

I was using this in a real project and it was working. It was abandoned and when I get it again it was full of upgrade issues with react and react-router. After all updates, I’m having this problem.

I tried to downgrade typescript but I still see this with ts-jest.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kulshekharcommented, May 19, 2017

@asfernandes I just tried this with typescript@2.4.0-dev.20170504 and it passed the test.

1reaction
vslinkocommented, May 7, 2017

@asfernandes please try typescript@2.4.0-dev.20170504

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct way to import lodash - Stack Overflow
js in the root of the regular 'lodash' package, and import has from 'lodash/has' (or const has = require ('lodash/has ) will load...
Read more >
TSConfig Option: esModuleInterop - TypeScript
This mis-match causes these two issues: the ES6 modules spec states that a namespace import ( import * as x ) can only...
Read more >
External Module Usage Case - Cocos Creator
The biggest problem with how to use npm in Cocos Creator 3.x is the ... package comes with a TypeScript declaration file, which...
Read more >
Externals - webpack
js indicates that the module jquery in import $ from 'jquery' should be excluded from bundling. In order to replace this module, the...
Read more >
Working with JavaScript in Visual Studio Code
Using the TypeScript language service, VS Code can provide smart ... most JavaScript projects without any configuration, you can make IntelliSense even more ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found