Move package.json up one dirctory in react app

Viewed 641

I have started learning react a few days ago, I use npx create-react-app frontend to create my react app when I do so I got this structure

-- demo
    -- frontend
        -- node_modules
        -- public
        -- src
        -- .gitignore
        -- package.json
        -- package-lock.json
        -- README.md

But what I hope to do is to move the package.json up one directory to get this structure

-- demo
    -- frontend
        -- node_modules
        -- public
        -- src
        -- .gitignore
        -- package-lock.json
        -- README.md
    -- package.json

But when I do so I can't start the development server it says react-scripts' is not recognized as an internal or external command and that is understandable because the react-scripts is defined in node_modules and they are now in another directory, I need to do that because heroku required package.json file be in the root folder and I need to integrate react with django, the root directory looks very messy last time when I put all django app folders and react folders in one root directory.

1 Answers

package.json reads from node_modules and both must be together, a better structure for the repo is to have a seperate pakage.json and node_modules, keep one package.json in frontend folder and one package.json in backend folder and so one

--repo
    --frontend
        --package.json
        --node_modules
    --backend 
        --node_modules
        --package.json
--readme
Related