Having git problem in React django project - reactjs

STATEMENT
I want to make project with django backend and React frontend. I have created a project using and then create a frontend react folder using create-react-app. Now I want to upload my projectname folder to my github repository. But when I add my files using git add . command from my root folder('projectname' folder). It shows some warnings given below. What should I do? Please help.
WARNING
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> frontend
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached frontend
COMMAND THAT I HAVE USED
$ virtualenv env
$ source env/bin/activate
$ pip install django
$ django-admin.py startproject projectname
$ cd django-react-demo
$ npm install -g create-react-app
$ create-react-app frontend
MY FOLDER STRUCTURE
projectname
│
└───frontend
│ ├──.node_modules
│ ├──public
│ ├──src
│ ├──gitignore
│ ├──README.md
│ ├──package.json
│ └──package_lock.json
│
│projectname
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── manage.py

You are seeing that error because you have a git repository nested inside another repository.
Your main project directory projectname has a .git directory, and the directory nested inside it frontend has another .git repo that create-react-app created. The git repo inside another repo is called a submodule. It's possible to work with submodules, but it has its own quirks.
The easiest way to get around your error is to use only one git repo in your main project directory and delete the .git directory inside frontend directory. Try the following steps:
Go into the frontend directory.
cd frontend
Delete the .git directory inside frontend directory.
rm -rf .git
Go back to your main project directory.
You should now be able to track all files inside the frontend directory inside your main directory.

Maybe your react project i.e. frontend is also a git repository. So, what you can do is, put the frontend on the outside of the projectname folder and use the API key that you have from the backend in the frontend for your work.
You can follow this link:
https://www.digitalocean.com/community/tutorials/build-a-to-do-application-using-django-and-react

Related

Mern Project Folder structure help neeeded

root/
├─ frontend/
├─ backend/
.gitignore
.git/
I have a root folder and inside of that root i have two folders one is frontend and another one is backend. and i have git initialize on the root folder. Now I want to deploy frontend on firebase and backend on the heroku. The problem is that to deploy backend on herko 'coz it'll ask me to git initialize. how to handle this situation.

How to Start a React or a Node Application from a different directory using a Shell Script in Ubuntu

I want to start a React web application using a Shell script located at a different place in the same project. The project directory structure looks like follows.
project/
├── bin/
│   └── start.sh
├── config/
│   └── app.config
├── lib/
   ├── react_app/
Here's the relevant code segment of the shell script bin/start.sh
#!/bin/bash
# load configurations
REACT_APP_WEBSOCKET_PORT=8015=$(cat ../config/app.yaml | shyaml get-value websocket_port)
# start the react applications
REACT_APP_WEBSOCKET_PORT=$REACT_APP_WEBSOCKET_PORT ../lib/react_app npm start
The shell command I'm using seems to be incorrect. Any help?
Here's the error log.
./start.sh: line 38: ../lib/react_app: Is a directory
The command ../lib/react_app npm start is trying to launch executable react_app with arguments npm start, which is a directory, not a file.
I would just cd into the directory, like so:
#!/bin/bash
# load configurations
REACT_APP_WEBSOCKET_PORT=8015=$(cat ../config/app.yaml | shyaml get-value websocket_port)
cd ../lib/react_app
# start the react applications
REACT_APP_WEBSOCKET_PORT=$REACT_APP_WEBSOCKET_PORT npm start

How do I push a node project to GitHub that contains a create-react-app in a subfolder?

I'm currently working on my first MERN app. I have some issues regarding pushing my app to GitHub. My app file structure is as follows:
├───myApp
│ ├───server.js
│ ├───connection.js
│ ├───controls
│ ├───models
│ ├───client <-- create-react-app folder
I know that using create-react-app will run git init as well. So, if I try to get my full app on GitHub I will get a git repo inside a git repo:
Is there a way to remove git from the create-react-app and push my whole app to one repo?
Thanks
Fixed the issue by deleting the .git folder inside the client
On github, you will be able to deploy only the react app. Not your backend.
The easiest way is to deploy to a gh-branch branch the dist folder created by create-react-app when you run the build command.

Linking and using local UI module in react-native

Disclaimer; I am new to react & react-native. I've downloaded a UI module and am attempting to use it in my project. This is what the folder structure looks like:
├── myProject
│   ├── README.md
│   └── src
│   └── client
│   └── {actual react-native project}
└── react-native-ui-module
├── node_modules
├── package-lock.json
├── package.json
└── src
I've added react-native-ui-module to myProject/src/client/package.json like so:
"react-native-ui-module": "file:../../../react-native-ui-module",
From there, I've executed the following command:
$ npm install
$ react-native link
I can see the module in node_modules after the above steps.
I've expected to then use the module like so:
import { Button } from 'react-native-ui-module';
However, I'm getting an error that states that the Modulereact-native-ui-module` does not exist in the Haste module map. I've tried following the error message's suggestion, which is:
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
Clear watchman watches: watchman watch-del-all.
Delete the node_modules folder: rm -rf node_modules && npm install.
Reset Metro Bundler cache: rm -rf /tmp/metro-bundler-cache-* or npm start -- --reset-cache.
Remove haste cache: rm -rf /tmp/haste-map-react-native-packager-*.
I've also tried using relative and absolute paths in the import statement. Is there a better way of importing and installing the module? And what other troubleshooting steps can I take to actually use the module?
Also, to clarify; this is a module that I've purchased and manually downloaded, so it's not available from npmjs.
The short thing you can do, considering your current situation, is to copy the ui module into the node_modules of your {actual react-native project}, then the ui module will be available for you to use in the imports, in this way you don't even need to add the module into your package.json, but this way is just for testing what the ui module can do.
The correct way is to find this ui module in the npm site, and use the command npm install --save [name-of-the-ui-module], then ui module will be available for you to use in your imports.
(Updated considering comments bellow)
To avoid Headaches with npm, considering that your library is not in the npm repository, you can also include this library in a lib folder into your project, and use it like you were using any other component.

How do I make vendoring work with Google App Engine?

I am trying to introduce Go vendoring (storing dependencies in a folder called vendor) to an existing App Engine project. I have stored all dependencies in the vendor folder (using Godep as a helper) and it looks right, but running the application locally I get the following error:
go-app-builder: Failed parsing input: package "golang.org/x/net/context" is imported from multiple locations: "/Users/erik/go/src/github.com/xyz/abc/vendor/golang.org/x/net/context" and "/Users/erik/go/src/golang.org/x/net/context"
I believe the two locations should resolve to the same location, as Go applications should look in the vendor folder first. Is there a way to make Appengine understand that both dependencies are the same?
Your project directory (where app.yaml is) is probably in the GOPATH/src.
It shouldn't be.
The go-app-builder will take everything in the app.yaml folder (and below) and additionally merge your GOPATH into it, meaning now you have it twice.
The solution is to move app.yaml out of the GOPATH/src folder.
Additionally you'll find that goapp test works differently from goapp serve and goapp deploy when it comes to resolving dependencies.
So this is the solution I have been using (haven't used golang app engine in a while already) and it's the only setup I've found to work properly for all the goapp commands and for govendor to work properly (not sure about godep)
/GOPATH
├──/appengine
| ├── app.yaml
| └── aeloader.go
└──/src
└── /MYPROJECT
├── main.go
├── /handler
| └── handler.go
└── /vendor
details:
file: GOPATH/appengine/aeloader.go (NOTE the init function is necessary, probably a bug though)
package mypackage
import (
_ "MYPROJECT"
)
func init() {
}
now run goapp serve and goapp deploy from ../GOPATH/appengine/ and goapp test ./... from ../GOPATH/src/MYPROJECT
P.S. I find the global GOPATH thing silly and simply set my GOPATH to current project folder (in the example above /GOPATH) and check the whole thing into version control.
I use a Makefile to move the vendor directory to a temporary GOPATH:
TMPGOPATH := $(shell mktemp -d)
deploy:
mv vendor $(TMPGOPATH)/src
GOPATH=$(TMPGOPATH) gcloud app deploy
mv $(TMPGOPATH)/src vendor
I store this Makefile at the root of my service near the vendor directory and simply use make deploy to deploy manually or from the CI.
It works with Glide, Godeps or any tool that respects the Go vendor spec.
Please note, that you really need to move the vendor directory out of the build directory, otherwise the GoAppEngine compiler will try to build the vendor dependencies, potentially causing compile errors.
I just ran into this issue myself actually. The problem occurs when you're using the App Engine tools to build any package which imports something that is using vendoring, but the package you're trying to run doesn't have the import within it's vendor directory.
So, for example, if I'm trying to run package foo, which imports package bar, and both of which use the github.com/gorilla/mux library, if the bar repository has a vendor/ directory that contains gorilla/mux, but the foo package doesn't have gorilla mux in it's vendor/ directory, this error will occur.
The reason this happens is that the bar package will prioritize it's own vendor package over the one in the GOPATH, which is what foo will be using, causing a difference in the actual location of the imported paths.
The solution I found to this issue is to make sure that the foo directory is in the GOPATH and has the vendor directory properly installed. It's important to note that the vendor/ convention only works from within the GOPATH.
I managed to resolve this error using govendor instead of Godeps. The root cause appears to have been that vendored references with their own vendored references was not resolved correctly by Godeps.
The answer provided by Su-Au Hwang is also correct - you do have to keep app.yaml separate from your source.
Also got the same problem.
In the docs Google suggests the following:
For best results, we recommend the following:
Create a separate directory in your app's directory for each service.
Each service's directory should contain the service's app.yaml file and one or more .go files.
Do not include any subdirectories in a service's directory.
Your GOPATH should specify a directory that is outside your app's directory and contain all the dependencies that your app imports.
But this messes up my project structure, which looks like this:
GOPATH/
└── src
└── github.com
└── username
└── myproject
├── app.yaml
├── cmd
│   └── myproject
│   └── main.go
├── handlers
│   └── api.go
├── mw
│   ├── auth.go
│   └── logger.go
└── vendor
Where the myproject directory is a git project and the vendor folder contains all dependencies.
Running gcloud deploy from the myproject directory where app.yaml file lives doesn't work because first, main.go file is not in the same directory and second (from the same doc):
you must be careful not to place your source code at or below your app's directory where the app.yaml file is located
What I ended up doing is building my own custom runtime instead, which turned out to be a very clean solution.
Simply generate the Dockerfile with the following command:
gcloud beta app gen-config --custom
Modify it, then specify runtime: custom in your app.yaml and deploy normally.
The trick here is of course that you're in control what gets copied where.
Here is my Dockerfile:
# Dockerfile extending the generic Go image with application files for a
# single application.
FROM gcr.io/google-appengine/golang
ENV GOPATH /go
# The files which are copied are specified in the .dockerignore file
COPY . /go/src/github.com/username/myproject/
WORKDIR /go/src/github.com/username/myproject/
RUN go build -o dist/bin/myproject ./cmd/myproject
# All configuration parameters are passed through environment variables and specified in app.yaml
CMD ["/go/src/github.com/username/myproject/dist/bin/myproject"]
Don't forget that App Engine expects your application listening on port 8080. Check out Building Custom Runtimes doc for more details.

Resources