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
  • Merge requests
  • !7991

Support templates in scoped packages

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/klasbj/templates-in-scoped-packages into master Nov 17, 2019
  • Overview 5
  • Commits 4
  • Pipelines 0
  • Changes 1

Created by: klasbj

Fixing issue #7985 (closed).

I learned a bit about some... interesting... NPM behavior while testing. With only a regex check that the package name started with cra-template-, it still fell back to cra-template-@scope/package. If scope/package happened to be an accessible Github project, npm would download and install some version (I'm not quite sure how it decided which version...) of that repository as the template.

The solution I came up with was adding the prefix to the package name, while leaving the scope part unchanged. Maybe not 100% intuitive, but consistent with the behaviour of non-scoped packages.

Test cases

Plain, uses cra-template

CRA_INTERNAL_TEST=1 yarn create-react-app my-app1
# [...]
# Creating a new React app in /home/klasse/projects/create-react-app/my-app1.
#
# Installing packages. This might take a couple of minutes.
# Installing react, react-dom, and react-scripts with cra-template...
# [...]

Template without prefix (typescript), uses cra-template-typescript

CRA_INTERNAL_TEST=1 yarn create-react-app --template typescript my-app2
# [...]
# Creating a new React app in /home/klasse/projects/create-react-app/my-app2.
#
# Installing packages. This might take a couple of minutes.
# Installing react, react-dom, and react-scripts with cra-template-typescript...
# [...]

Template with prefix (cra-template-typescript)

CRA_INTERNAL_TEST=1 yarn create-react-app --template cra-template-typescript my-app3
# [...]
# Creating a new React app in /home/klasse/projects/create-react-app/my-app3.
#
# Installing packages. This might take a couple of minutes.
# Installing react, react-dom, and react-scripts with cra-template-typescript...
# [...]

Template in scoped npm package with prefix (@klasbj/cra-template-scoped)

CRA_INTERNAL_TEST=1 yarn create-react-app --template "@klasbj/cra-template-scoped" my-app4
# [...]
# Creating a new React app in /home/klasse/projects/create-react-app/my-app4.
#
# Installing packages. This might take a couple of minutes.
# Installing react, react-dom, and react-scripts with @klasbj/cra-template-scoped...
# [...]

Template in scoped npm package without prefix (@klasbj/scoped), uses @klasbj/cra-template-scoped

CRA_INTERNAL_TEST=1 yarn create-react-app --template "@klasbj/scoped" my-app5
# [...]
# Creating a new React app in /home/klasse/projects/create-react-app/my-app5.
#
# Installing packages. This might take a couple of minutes.
# Installing react, react-dom, and react-scripts with @klasbj/cra-template-scoped...
# [...]

Scoped template with matching Github project, attempts to use @klasbj/cra-template-scoped-cra-template, and not my Github project klasbj/scoped-cra-template

CRA_INTERNAL_TEST=1 yarn create-react-app --template "@klasbj/scoped-cra-template" my-app6
# [...]
# Creating a new React app in /home/klasse/projects/create-react-app/my-app6.
#
# Installing packages. This might take a couple of minutes.
# Installing react, react-dom, and react-scripts with @klasbj/cra-template-scoped-cra-template...
#
# [1/4] Resolving packages...
# error An unexpected error occurred: "https://registry.yarnpkg.com/@klasbj%2fcra-template-scoped-cra-template: Not found".
# info If you think this is a bug, please open a bug report with the information provided in "/home/klasse/projects/create-react-app/my-app6/yarn-error.log".
# info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
#
# Aborting installation.
#   yarnpkg add --exact react react-dom /home/klasse/projects/create-react-app/packages/react-scripts/react-scripts-3.2.0.tgz @klasbj/cra-template-scoped-cra-template --cwd /home/klasse/projects/create-react-app/my-app6 has failed.
#
# Deleting generated file... package.json
# Deleting generated file... yarn.lock
# Done.
# [...]
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/klasbj/templates-in-scoped-packages