Skip to content
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

Allow private npm packages as templates #8425

Closed
itelo opened this issue Feb 4, 2020 · 8 comments
Closed

Allow private npm packages as templates #8425

itelo opened this issue Feb 4, 2020 · 8 comments

Comments

@itelo
Copy link

itelo commented Feb 4, 2020

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"
@ianschmitz
Copy link
Contributor

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

@itelo
Copy link
Author

itelo commented Feb 6, 2020

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

@ricardoamedeiros
Copy link

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...


> [email protected] 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

> [email protected] 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

> [email protected] 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

> [email protected] postinstall /Users/ricardo/workspace/my-app/node_modules/babel-runtime/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


> [email protected] postinstall /Users/ricardo/workspace/my-app/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


> [email protected] postinstall /Users/ricardo/workspace/my-app/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
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?

@ricardoamedeiros
Copy link

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

not working.

@ricardoamedeiros
Copy link

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] }) );

@mrmckeb
Copy link
Contributor

mrmckeb commented Apr 29, 2020

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

@ricardoamedeiros
Copy link

with field main worked.

@mrmckeb
Copy link
Contributor

mrmckeb commented Apr 29, 2020

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

@mrmckeb mrmckeb closed this as completed Apr 29, 2020
@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

4 participants