Skip to content

Custom template cannot be created from local path #8893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
emoriarty opened this issue Apr 25, 2020 · 1 comment
Closed

Custom template cannot be created from local path #8893

emoriarty opened this issue Apr 25, 2020 · 1 comment

Comments

@emoriarty
Copy link

Describe the bug

When creating a new react-app with a custom local template fails because cannot find the provided module.

Error: Cannot find module 'cra-template-myapp'                                                                                                                                                              
Require stack:                                                                                                                                                                                              
- /Users/enrique/Workspace/test-cra/your-app/node_modules/react-scripts/scripts/init.js                                                                                                              
- /Users/enrique/Workspace/test-cra/your-app/[eval]                                                                                                                                                  
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)                                                                                                                             
    at Function.resolve (internal/modules/cjs/helpers.js:78:19)                                                                                                                                             
    at module.exports (/Users/enrique/Workspace/test-cra/your-app/node_modules/react-scripts/scripts/init.js:110:13)                                                                                 
    at [eval]:3:14                                                                                                                                                                                          
    at Script.runInThisContext (vm.js:131:20)                                                                                                                                                               
    at Object.runInThisContext (vm.js:297:38)                                                                                                                                                               
    at Object.<anonymous> ([eval]-wrapper:10:26)                                                                                                                                                            
    at Module._compile (internal/modules/cjs/loader.js:1147:30)                                                                                                                                             
    at evalScript (internal/process/execution.js:94:25)                                                                                                                                                     
    at internal/main/eval_string.js:23:3 {                                                                                                                                                                  
  code: 'MODULE_NOT_FOUND',                                                                                                                                                                                 
  requireStack: [                                                                                                                                                                                           
    '/Users/enrique/Workspace/test-cra/your-app/node_modules/react-scripts/scripts/init.js',                                                                                                         
    '/Users/enrique/Workspace/test-cra/your-app/[eval]'                                                                                                                                              
  ]                                                                                                                                                                                                         
}

I also cloned the create-react-app repo to install from local the cra-template-typescript and the same error happens.

Which terms did you search for in User Guide?

I followed the official doc on this matter.

Environment

Environment Info:

  current version of create-react-app: 3.4.1
  running from /Users/enrique/.npm/_npx/65740/lib/node_modules/create-react-app

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
  Binaries:
    Node: 13.11.0 - ~/.nodenv/versions/13.11.0/bin/node
    Yarn: Not Found
    npm: 6.13.7 - ~/.nodenv/versions/13.11.0/bin/npm
  Browsers:
    Chrome: 81.0.4044.122
    Firefox: 75.0
    Safari: 13.1
  npmPackages:
    react: Not Found
    react-dom: Not Found
    react-scripts: Not Found
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

After creating the cra-template-myapp folder, I run the next command as the docs says:

npx create-react-app your-app --template file:../cra-template-myapp

Expected behavior

The new react app can be created from a local template.

Actual behavior

create-react-app crashes when a custom template installed locally is passed to --template parameter.

@emoriarty
Copy link
Author

emoriarty commented Apr 25, 2020

Ok. False alarm. I figured it out what's the issue.

The package.json should explicitly declare the main property pointing to the template.json file. I found it by looking at the cra-template-redux repo. I was looking at first at cra-template-typescript and did not include the main prop. My bad.

Anyway, I know that I had forgotten that node packages should export the main entry file but I think it should be great (and helpful) including this small detail in the official guide.

UPDATE: I leave here the PR updating the doc as I mentioned in the previous paragraph. Hope it helps.

@lock lock bot locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant