Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #579
Closed
Open
Issue created Sep 05, 2016 by Administrator@rootContributor

npm test fails with assets imported from node_modules folder

Created by: robcaldecott

I have published a number of in-house components that package up CSS and images so they can be included in a Webpack project like this:

import MyComponent from 'my-component'
import 'my-component/css/Styles.css'
import logo from 'my-component/img/CorporateLogo.png'

This has worked great with CRA and my apps run and build correctly.

However, any attempt to test code that includes CSS/images in this way with CRA 0.4.1 will fail - almost as if testing treats anything imported from node_modules as JavaScript.

e.g. when running a test of a component that imports a PNG from node_modules/my-component/img:

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

    C:\Users\<user>\Projects\my-app\node_modules\my-component\img\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)

Any ideas or workarounds would be welcome.

Assignee
Assign to
Time tracking