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
  • #10513
Closed
Open
Issue created Feb 05, 2021 by Administrator@rootContributor

Test fails with `@` in the SVG filename

Created by: nvh95

Describe the bug

If we import an SVG which filename contains some characters like @, react-scripts test will fail. For example logo@2x.svg. The reason is when packages/react-scripts/config/jest/fileTransform.js transforms logo@2x.svg to a component with the name of SvgLogo@2X (see image bellow). It is not a valid component name (or javascript variable). I am putting a PR to fix this by converting a character which is non-letter, non-number, non-underscore, into an ASCII number. Please see #10514

Environment

Environment Info:

  current version of create-react-app: 4.0.2
  running from /Users/henry/.npm/_npx/57393/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v12.20.1/bin/npm
  Browsers:
    Chrome: 88.0.4324.150
    Edge: Not Found
    Firefox: 84.0
    Safari: 13.1.3
  npmPackages:
    react: ^17.0.1 => 17.0.1 
    react-dom: ^17.0.1 => 17.0.1 
    react-scripts: 4.0.2 => 4.0.2 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

Just import an image with the filename of logo@2x.svg

import logo2 from './logo@2x.svg';
  • https://github.com/nvh95/create-react-app-reproduce/blob/reproduce-file-transform-failed/src/App.js#L1
  • https://github.com/nvh95/create-react-app-reproduce/blob/reproduce-file-transform-failed/src/App.test.js
git clone https://github.com/nvh95/create-react-app-reproduce
yarn
yarn test -- --watchAll

Expected behavior

The test should pass

Actual behavior

The test failed Screenshot 2021-02-05 at 23 40 31

Reproducible demo

  • https://github.com/nvh95/create-react-app-reproduce/blob/reproduce-file-transform-failed/src/App.js#L1
  • https://github.com/nvh95/create-react-app-reproduce/blob/reproduce-file-transform-failed/src/App.test.js
Assignee
Assign to
Time tracking