Skip to content

Allow private npm packages as templates #8425

Closed

Description

@itelo

Is your proposal related to a problem?

No. I just had to create a project like CRA in my work and we allowed private repositories. I want to know if it is a thing that the CRA community wants in the CLI. If it's ok I could work in a PR.

Describe the solution you'd like

probally a flag like:

npx create react-app --template some-template-name --npm-access-token="123"

Activity

  1. ianschmitz commented on Feb 6, 2020

    @ianschmitz
    Contributor

    Supporting this use case sounds reasonable, but couldn't it be solved through existing methods such as a .npmrc file?

  2. itelo commented on Feb 6, 2020

    @itelo
    Author

    hmmm, I didn't know about .npmrc file, I believe puting the access token there should work fine.

  3. ricardoamedeiros commented on Apr 11, 2020

    @ricardoamedeiros

    Supporting this use case sounds reasonable, but couldn't it be solved through existing methods such as a .npmrc file?

    Hi,

    Even configuring the .npmrc correctly, at the end of the build the customization module is not found in the private npm.

    log:

    $ npx create-react-app my-app --template sebrae
    
    Creating a new React app in /Users/ricardo/workspace/my-app.
    
    Installing packages. This might take a couple of minutes.
    Installing react, react-dom, and react-scripts with cra-template-sebrae...
    
    
    > fsevents@1.2.12 install /Users/ricardo/workspace/my-app/node_modules/jest-haste-map/node_modules/fsevents
    > node-gyp rebuild
    
      SOLINK_MODULE(target) Release/.node
      CXX(target) Release/obj.target/fse/fsevents.o
      SOLINK_MODULE(target) Release/fse.node
    
    > fsevents@1.2.12 install /Users/ricardo/workspace/my-app/node_modules/watchpack/node_modules/fsevents
    > node-gyp rebuild
    
      SOLINK_MODULE(target) Release/.node
      CXX(target) Release/obj.target/fse/fsevents.o
      SOLINK_MODULE(target) Release/fse.node
    
    > fsevents@1.2.12 install /Users/ricardo/workspace/my-app/node_modules/webpack-dev-server/node_modules/fsevents
    > node-gyp rebuild
    
      SOLINK_MODULE(target) Release/.node
      CXX(target) Release/obj.target/fse/fsevents.o
      SOLINK_MODULE(target) Release/fse.node
    
    > core-js@2.6.11 postinstall /Users/ricardo/workspace/my-app/node_modules/babel-runtime/node_modules/core-js
    > node -e "try{require('./postinstall')}catch(e){}"
    
    
    > core-js@3.6.5 postinstall /Users/ricardo/workspace/my-app/node_modules/core-js
    > node -e "try{require('./postinstall')}catch(e){}"
    
    
    > core-js-pure@3.6.5 postinstall /Users/ricardo/workspace/my-app/node_modules/core-js-pure
    > node -e "try{require('./postinstall')}catch(e){}"
    
    + react-scripts@3.4.1
    + react-dom@16.13.1
    + react@16.13.1
    + cra-template-sebrae@1.0.1
    added 1811 packages from 770 contributors in 102.158s
    
    58 packages are looking for funding
      run `npm fund` for details
    
    internal/modules/cjs/loader.js:638
        throw err;
        ^
    
    Error: **Cannot find module 'cra-template-sebrae'**
        at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
        at Function.resolve (internal/modules/cjs/helpers.js:33:19)
        at module.exports (/Users/ricardo/workspace/my-app/node_modules/react-scripts/scripts/init.js:110:13)
        at [eval]:3:14
        at Script.runInThisContext (vm.js:122:20)
        at Object.runInThisContext (vm.js:329:38)
        at Object.<anonymous> ([eval]-wrapper:6:22)
        at Module._compile (internal/modules/cjs/loader.js:776:30)
        at evalScript (internal/bootstrap/node.js:589:27)
        at startup (internal/bootstrap/node.js:265:9)
    
    Aborting installation.
      node  has failed.
    
    Deleting generated file... node_modules
    Deleting generated file... package.json
    Done.

    Custom template at nexus:

    image

    .npmrc config:

    image

    Any solution?

  4. ricardoamedeiros commented on Apr 11, 2020

    @ricardoamedeiros

    hmmm, I didn't know about .npmrc file, I believe puting the access token there should work fine.

    not working.

  5. ricardoamedeiros commented on Apr 22, 2020

    @ricardoamedeiros

    I discovered the problem. The template path within node_modules was not being found. I made the pull request with the following adjustment:

    javascript:

    create-react-app/packages/react-scripts/scripts/init.js

    befor:

    const templatePath = path.dirname( require.resolve(${templateName}/package.json, { paths: [appPath] }) );

    after:

    const templatePath = path.dirname( require.resolve(${templateName}/package.json, { paths: [${appPath}/node_modules] }) );

  6. mrmckeb commented on Apr 29, 2020

    @mrmckeb
    Contributor

    Hi @itelofilho, can you please confirm that your template has a main field?

    We've resolve this issue, but until our next release, templates must have a main field - which is required by require.resolve. See:
    e0b179c#diff-1453d9590326c639309801105bc967c2

  7. self-assigned this
    on Apr 29, 2020
  8. ricardoamedeiros commented on Apr 29, 2020

    @ricardoamedeiros

    with field main worked.

  9. mrmckeb commented on Apr 29, 2020

    @mrmckeb
    Contributor

    Closing this off, thanks for confirming. We'll release the fix for this soon, sorry again.

  10. locked and limited conversation to collaborators on May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions