简体   繁体   中英

Next.js gives missing script on all npm run commands

I am creating a Next.js project as I follow along in a Udemy class. I have the following package.json

{
  "name": "nextjsdemo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "next": "^9.0.2",
    "react": "^16.8.6",
    "react-dom": "^16.8.6"
  }
}

My directory structure is as follows below.

在此处输入图像描述

npm install --save next react react-dom

When I run the command

npm run dev

I receive the error:

npm ERR! missing script: dev

I receive a similar error on npm run build as well.

What am I doing incorrectly?

Thanks,

Edit 1 The only way I could get this to work was to downgrade next to V4.2.3. This seems strange that the latest version does not work.

The problem might be your file structure. Try and check if you are in the same folder that holds the package.json file. A common mistake is to have a parent folder (say user/next-demo) that then holds a child folder with your nextJs project (say user/next-demo/next-demo) and then trying to run the next scripts in the parent folder.

此问题的解决方案是遵循github.com/zeit/next.js/#setup上的设置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM