Package.json not found

I have tried many variations of the build settings, but they have all failed. I have tried setting my base directory to nothing, /ToDo, and /ToDo/ToDo. I have tried the same for my publish directory but also with /build at the end and currently have it as just build. It does not think my package.json file exists even though it it in the /ToDo folder clearly. Any idea why this would be the case?

Site (not currently working):
https://visionary-kashata-7a98ba.netlify.app/

Repo:
Github link

Build settings:
Base directory: not set
Build command: CI= npm run build
Publish Directory: build

Error:
12:03:22 PM: $ npm run build
12:03:22 PM: npm ERR! code ENOENT
12:03:22 PM: npm ERR! syscall open
12:03:22 PM: npm ERR! path /opt/build/repo/package.json
12:03:22 PM: npm ERR! errno -2
12:03:22 PM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
12:03:22 PM: npm ERR! enoent This is related to npm not being able to find a file.
12:03:22 PM: npm ERR! enoent
12:03:22 PM: npm ERR! A complete log of this run can be found in:
12:03:22 PM: npm ERR! /opt/buildhome/.npm/_logs/2023-03-14T16_03_22_271Z-debug-0.log
12:03:22 PM: ​
12:03:22 PM: “build.command” failed
12:03:22 PM: ────────────────────────────────────────────────────────────────
12:03:22 PM: ​
12:03:23 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
12:03:22 PM: Error message
12:03:22 PM: Command failed with exit code 254: npm run build (Search results for '"non-zero exit code: 254"' - Netlify Support Forums)
12:03:22 PM: ​
12:03:22 PM: Error location
12:03:22 PM: In Build command from Netlify app:
12:03:22 PM: npm run build
12:03:22 PM: ​
12:03:22 PM: Resolved config
12:03:22 PM: build:
12:03:22 PM: command: npm run build
12:03:22 PM: commandOrigin: ui
12:03:22 PM: environment:
12:03:22 PM: - NETLIFY_GRAPH_TOKEN
12:03:22 PM: - ONEGRAPH_AUTHLIFY_TOKEN
12:03:22 PM: publish: /opt/build/repo/build
12:03:22 PM: publishOrigin: ui

Hi @adamprinciotta, kindly follow the steps below to resolve your problem.

First of all change your base directory by clicking on your site’s name in the Netlify dashboard UI → Then click on the Site settings button → Then click on the Build & deploy link in the left pane menu → Then click on the Edit settings button by scrolling down to the Build settings section → Then type ToDo in the Base directory input field. → Click on the Save button to complete.

ToDo is a sub-directory in the root of your project hence the reason for setting ToDo as the base directory in the deploy settings.

Once you are done setting the base directory by following the suggestions above, kindly add the environment variables by following the steps below.

  1. Go to your project in Netlify and click on your site name.
  2. Click on the Site settings button or tab on the right most side of the menu.
  3. Click on Environment variables (New) on the left pane menu.
  4. Click on the Add Variable button.
  5. Type CI into the key input field, and then type false into the values field, and then click on the Create variable button.
  6. Repeat the steps from step 4 to add another Environment variable by setting the key input to NPM_FLAGS and set values input to --legacy-peer-deps.
  7. Once you are done click on the Deploys tab menu at the top of the page and then click on the Trigger deploy button and select Clear cache and deploy site option.

Let me know the outcome.

Thanks.

Thank you, that allowed it to run. However, instead or running my app.jsx, just displays the index.html. I tried changing the build command to npm run build since I used vite to set it up, but that also just runs the index.html file. Do you know if I can just alter the index.html file to call these other files or if there is a better command for having it run?

Hi @adamprinciotta, thanks for letting me know my suggestion helped.

Regarding your question, the way react works is different from regular HTML websites.
React is a single page application therefore App.jsx is the root component. When React is building your site, conceptually the root component is injected into the index.html and then rendered.

Also any child component within the root component (App.jsx) will be injected into the index.html and then rendered as well.

Since your website is a one page website, you designed it in a way that when the menu links are clicked you will be navigated to a section of the page.

However I am assuming you also want routing to different pages instead of scrolling to a section on the main page.
At the end of the day it is still a single page application that just gives you the illusion that you have navigated to a new page when a menu link is clicked. What happens is that the child component is just swapped with another child component.
You can build routing yourself however there are easier alternatives such as using packages so that you don’t reinvent the wheel.

If you want to implement page routing in React you can use packages such as React Router.
Learn more about React Router at

You can also read more about how React Router works at

Hope the above explanation helps.

Thanks.

I designed the project to be a single page web application, just multiple components handling different sections/functions of the page. I believe all of this stems from my app.jsx. I may be misunderstanding, but it sounds like you’re saying the app.jsx is injected into the index.html then run? If that’s the case it doesn’t seem to be working. It’s just odd that on my local host, it works just fine. But when it’s run here it just does the index.js and not the app.jsx

@adamprinciotta In general, there’s nothing particularly odd about builds “working locally” and not when deployed.

The is because most site builders do something entirely different when they’re performing a “build” than when they run their development server.

So it’s rarely an “apples & apples” comparison.

With a standard static site (not relying on functions), a much closer comparison is to run your npm run build command locally, then go into the appropriate output folder and run npx serve.

You should see the same behaviour there that you do on Netlify.

Checking your repository myself, I see a Sign in with Google button after a build, is that not what should be showing?

Is there something in particular not working?

1 Like

Hi @adamprinciotta, thanks for the additional feedback.

I do not see any index.js in your repository.
The only file that I am assuming might be the index is main.jsx. Correct me if I am wrong.

In the main.jsx your code is injecting the App.tsx into the index.html

Now when you take a look inside App.tsx you notice the components that might render is the SignOut and GrabData in div or a SignIn component due to conditional rendering.

Sign in with Google is the first component that will be rendered.
The above is exactly what should happen after it has been deployed as well.

Once you are signed in with Google, a session is stored so anytime you revisit the site the SignOut and GradData components will be rendered.
Once you sign out only the SignIn component with be rendered.

If the above explanation does not make things clear, I recommend you go through your code from the App.tsx file and then investigate the children components that get rendered to understand the sequence of components that get rendered.

Else kindly explain what exactly you want to achieve.

Thanks.

On the netlify build, I just see a blank page. Does it show you the sign in page on the website or on the localhost if you downloaded the github?

I apologize, I meant to say that it renders the index.html which is essentially blank rather than the App.jsx. The App.jsx is run through the main.jsx so I guess neither of them is being run. I do want it so that they have to sign in before using it and that components are run conditionally. I am still need to make the sign in page look better, but right now it doesn’t load for me at all. Do you see the sign in with google button on the page?

Hi @adamprinciotta, I cloned your site and then deployed it at my end and it displays the Sign in with Google button.
https://jade-vacherin-f423dd.netlify.app/

I suggest you delete your current deploy and then redeploy again to see if it works.

Kindly make sure when you are deploying your site you add the environment variables below by clicking on the Advanced settings button.

  • Type CI into the key input field, and then type false into the values field, and then click on the Create variable button.

  • Add another Environment variable by setting the key input to NPM_FLAGS and set values input to --legacy-peer-deps

Thanks.

I already had those environment variables set up from a previous reply but they did not work. Did I do something wrong?

Hi @adamprinciotta, you are not doing anything wrong. I am suggesting you create a fresh deploy to see if the problem persists. You can add another copy of the site and still keep the current deploy.
Thanks.

I added a new site with the same repo, did the environment variables the way they should be, and it still loads a blank page. Just to clarify, the build command you did was npm run build?

Hi @adamprinciotta, yes the build settings I used is npm run build.

Have you changed your base directory to ToDo?

Kindly check the image below to see my build settings.

Let me know the outcome.

Thanks.

The difference looks like it was the publish directory. I did not have it set to ToDo/dist. It now works. Thank you very much!

1 Like

Hi @adamprinciotta, glad to know my suggestions helped to resolve the problem.

Thanks.