Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 26, 2019. It is now read-only.
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

import returns undefined when running tests #364

Closed
@bagilevi

Description

@bagilevi

Is this a bug report?

Yes

Can you also reproduce the problem with npm 4.x?

Yes

Which terms did you search for in User Guide?

test jest import require undefined

Environment

  1. npm ls react-scripts-ts (if you haven’t ejected): 2.16.0
  2. node -v: v9.7.1
  3. npm -v: 4.6.1 (also 6.1.0)
  4. yarn --version (if you use Yarn): 1.5.1
  5. npm ls react-scripts-ts (if you haven’t ejected): 2.16.0

Then, specify:

  1. Operating system: macOS Sierra 10.12.4
  2. Browser and version (if relevant): not relevant, the problem is when running tests

Steps to Reproduce

  1. create an app as normal and run tests
create-react-app my-app --scripts-version=react-scripts-tscd my-appgit init .yarnyarn test
  1. add lodash as a dependency and run tests
yarn add lodash
  1. importlodash inApp.jsx and try to call a function on it
import_from'lodash';constfoo=_.join(['f','oo']);
  1. Run tests.
yarnyarn test

Expected Behavior

Test should pass.

Actual Behavior

Test suite fails to run:

TypeError: Cannot read property 'join' of undefined

Reproducible Demo

https://github.com/bagilevi/cra-ts-import

Relevant diff:
bagilevi/cra-ts-import@3b986a0

Notes

If I useconst _ = require('lodash') the tests pass, but thenyarn start says "require statement not part of an import statement".

If I tryimport _ = require('lodash'), I get "Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.".

If I renamefoo.ts tofoo.js, the test passes, so the problem seems to be TypeScript-related.

I had the same issue trying to importpouchdb, so it's not justlodash, and they both work in the browser.

Any advice would be appreciated, I just recently started using TypeScript. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp