Skip to content

Assets imported from scoped folder treated as JS #1613

Closed
@robcaldecott

Description

@robcaldecott

I reported this in create-react-app:

facebook/create-react-app#579

If you use the Webpack feature to import an asset (CSS/images) from a scoped npm module then Jest will treat the asset as JS code and the test will fail.

import logo from '@myscope/my-component/logo.png'

Results in an error like this:

FAIL  src\App.test.js
  ● Test suite failed to run

    C:\Users\<user>\Projects\my-app\node_modules\@myscope\my-component\logo.png:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){�PNG
                                                                                             ^
    SyntaxError: Unexpected token ILLEGAL

      at transformAndBuildScript (node_modules\react-scripts\node_modules\jest-runtime\build\transform.js:284:10)
      at Object.<anonymous> (src\App.js:3:38)
      at Object.<anonymous> (src\App.test.js:3:38)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions