首页 > 解决方案 > 键入“npm start”时在 ubuntu 服务器上运行 webapp 时出错

问题描述

在我开始之前:

这是我的文件夹树:

├──frontend_webapp(reactjs)
│  ├─ .next
│  ├─ components
│  ├─ content
│  ├─ helper
│  ├─ pages
│  ├─ public
│  ├─ services
│  ├─ static
│  ├─ next.config
│  ├─ next-env.d
│  ├─ package.json
│  ├─ package-lock.json
│  ├─ tsconfig.json
│  ├─ node_modules(after the "npm install")

好的,所以我运行“npm install”并将“node_modules”添加到文件夹中,这是应该的。正确的?好的,太好了..然后我输入:"npm start"

这是我得到的错误代码:

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from /home/timmi/frontend_webapp/.env
info  - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
Error: Could not find a production build in the '/home/timmi/frontend_webapp/.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
    at Server.readBuildId (/home/timmi/frontend_webapp/node_modules/next/dist/next-server/server/next-server.js:150:355)
    at new Server (/home/timmi/frontend_webapp/node_modules/next/dist/next-server/server/next-server.js:3:120)
    at NextServer.createServer (/home/timmi/frontend_webapp/node_modules/next/dist/server/next.js:1:2935)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! create-next-app-default@0.1.0 start: `next start -H 0.0.0.0 -p ${PORT:-3000}`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the create-next-app-default@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/timmi/.npm/_logs/2021-05-19T08_56_18_773Z-debug.log

但是:如果我输入"npm run build",这是我得到的错误消息:

info  - Using webpack 4. Reason: custom webpack configuration in next.config.js https://nextjs.org/docs/messages/webpack5
Failed to compile.

./components/nav.tsx:6:8
Type error: Property 'key' does not exist on type '{ href: string; label: string; }'.

  4 |   { href: '//github.com/create-next-app/create-next-app', label: 'Github' }
  5 | ].map(link => {
> 6 |   link.key = `nav-link-${link.href}-${link.label}`
    |        ^
  7 |   return link
  8 | });
  9 |
info  - Checking validity of types .npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! create-next-app-default@0.1.0 build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the create-next-app-default@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/timmi/.npm/_logs/2021-05-19T08_59_16_406Z-debug.log

所以在这个阶段,问题似乎出在代码上,这让我产生疑问:

如果需要,这是我的"package.json"文件:

{
  "name": "create-next-app-default",
  "version": "0.1.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start -H 0.0.0.0 -p ${PORT:-3000}"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.35",
    "@fortawesome/free-brands-svg-icons": "^5.15.3",
    "@fortawesome/free-solid-svg-icons": "^5.15.3",
    "@fortawesome/react-fontawesome": "^0.1.14",
    "bootstrap": "^4.6.0",
    "formik": "^2.2.6",
    "js-cookie": "^2.2.1",
    "lodash": "^4.17.21",
    "next": "10.1.3",
    "react": "17.0.2",
    "react-bootstrap": "^1.5.2",
    "react-dom": "17.0.2",
    "react-nextjs-toast": "^1.2.5",
    "yup": "^0.32.9"
  },
  "devDependencies": {
    "@types/js-cookie": "^2.2.6",
    "@types/lodash": "^4.14.168",
    "@types/node": "^14.14.37",
    "@types/react": "^17.0.3",
    "sass": "^1.32.8",
    "typescript": "^4.2.3"
  }
}

我很想得到一些帮助,因为我现在陷入困境。

标签: node.jsreactjsnpmnext.js

解决方案


推荐阅读