My project using next.js ecommerce starter is not running locally

6 replies
Last updated: Feb 2, 2021
i have created a project using next.js ecommerce starter.I am not able to run it locally.
steps i followed.

vercel env pull
to rename .env filechanged delevelopment command in
vercel.com to
npm run dev

used
npm start
to start developement server which gives error

~/projects/e-commerce$ npm start

> sanity-template-nextjs-ecommerce@1.0.0 start /home/hussamkhatib/projects/e-commerce
> vercel dev

sh: 1: vercel: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! sanity-template-nextjs-ecommerce@1.0.0 start: `vercel dev`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the sanity-template-nextjs-ecommerce@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/hussamkhatib/.npm/_logs/2021-01-28T04_47_29_680Z-debug.log

AI Update

The error message is telling you exactly what's wrong - you have two issues to fix:

  1. Missing node_modules: You haven't installed the dependencies yet
  2. Vercel CLI not found: The vercel command isn't available

Here's how to fix this:

Step 1: Install dependencies

npm install

This will install all the packages listed in your package.json, including the project dependencies and the Vercel CLI (if it's in the dependencies).

Step 2: Install Vercel CLI globally (if needed)

If vercel still isn't found after npm install, you may need to install the Vercel CLI globally:

npm install -g vercel

Step 3: Run the development server

After installing dependencies, use the correct command. Looking at your error, the start script runs vercel dev, but for local Next.js development you typically want:

npm run dev

This should run the standard Next.js development server. If the project is configured to use vercel dev specifically, then after installing dependencies, you can use:

npm start

Quick Summary: The issue wasn't with your environment variables or Vercel configuration - you simply skipped the npm install step that installs all the project dependencies. The warning message even tells you this: "Local package.json exists, but node_modules missing, did you mean to install?". Always run npm install (or yarn install) right after cloning or creating a new project before trying to run it.

If you continue to have issues after installing dependencies, check the package.json file to see what scripts are actually available and what they do. The dev script is typically what you want for local development with Next.js and Sanity.

hi
user U
- looks like you might need to install the vercel tooling on local?
tried that ,i'm getting more errors
hussamkhatib@hussamkhatib-VPCEB44EA:~/projects/e-commerce$ npm start

> sanity-template-nextjs-ecommerce@1.0.0 start /home/hussamkhatib/projects/e-commerce
> vercel dev

Vercel CLI 21.2.1 dev (beta) — <https://vercel.com/feedback>
> NOTE: Requested port 3000 is already in use
> NOTE: Requested port 3001 is already in use
> Running Dev Command "npm run dev"

> sanity-template-nextjs-ecommerce@1.0.0 dev /home/hussamkhatib/projects/e-commerce
> concurrently "next --port $PORT" "cd studio && sanity start"

[1] @sanity/core not installed in current project
[1] Project-specific commands not available until you run `sanity install`
[1] 
[1] Error: "start" is not available outside of a Sanity project context.
[1] Run the command again within a Sanity project directory, where "@sanity/core"
[1] is installed as a dependency.
[1]     at D.runCommand (~/projects/e-commerce/node_modules/@sanity/cli/bin/sanity-cli.js:3254:1345)
[1]     at t.exports (~/projects/e-commerce/node_modules/@sanity/cli/bin/sanity-cli.js:1788:2295)
[1] cd studio && sanity start exited with code 1
[0] Browserslist: caniuse-lite is outdated. Please run:
[0] npx browserslist@latest --update-db
[0] Loaded env from /home/hussamkhatib/projects/e-commerce/.env
[0] ready - started server on <http://localhost:3002>
> Ready! Available at <http://localhost:3002>
[0] event - compiled successfully

.env file
# Created by Vercel CLI
VERCEL="1"
VERCEL_ENV="development"
VERCEL_URL=""
VERCEL_GIT_PROVIDER=""
VERCEL_GIT_REPO_SLUG=""
VERCEL_GIT_REPO_OWNER=""
VERCEL_GIT_REPO_ID=""
VERCEL_GIT_COMMIT_REF=""
VERCEL_GIT_COMMIT_SHA=""
VERCEL_GIT_COMMIT_MESSAGE=""
VERCEL_GIT_COMMIT_AUTHOR_LOGIN=""
VERCEL_GIT_COMMIT_AUTHOR_NAME=""
NEXT_PUBLIC_SANITY_DATASET="production"
SANITY_STUDIO_API_DATASET="production"
SANITY_STUDIO_API_PROJECT_ID="${the_id}"
NEXT_PUBLIC_SANITY_PROJECT_ID="${the_id}"

the scripts from package.json(root dir)
  "scripts": {
    "dev": "concurrently \"next --port $PORT\" \"cd studio && sanity start\"",
    "build": "echo 'Building Sanity to public/studio…' && cd studio && sanity build ../public/studio -y && cd .. && next build",
    "start": "vercel dev",
    "postinstall": "lerna bootstrap",
    "check-template": "sanity-template check"
  },
do let me know if the information is sufficient for answering
A couple thoughts on what's happening:
So what should happen (and looks like might not be...?) is that when you run
npm install
it should install all the dependencies for the root folder (your Next.js frontend). Once that's done, NPM should be automatically running the
postinstall
script, which will use Lerna to run npm install for the Sanity Studio in the
/studio
folder. That's one possibility. If that's what's breaking, the fix would be to run
npm run postinstall
and that should install the rest of what's necessary.
Other possibility, the dev script may not be properly moving into the
/studio
folder and may be trying to run
sanity start
inside the root, which technically isn't the studio application, so it's failing. If the above solution doesn't work, try running
npm start
in your root directory, and in another terminal window, run
sanity start
inside the
/studio
folder.
If either of those things are happening, it's something we'll want to look into fixing with the starter's scripts, but hopefully one of those solutions will get you running
oh yes ! ,such a silly mistake my me . i forgot to run
npm run
.finally i can see my studio working too
.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?