首页 > 解决方案 > Linux 上的 NextJS + web pack 构建问题

问题描述

尝试将 next.js 项目从我的本地计算机部署到数字海洋上的 Ubuntu 服务器。在服务器上运行next build时,我收到以下 webpack 错误。但是在本地构建时我没有任何问题。调查这听起来像是一个节点问题,但在尝试了几个版本的节点后我无法确定问题。

(node:10557) UnhandledPromiseRejectionWarning: Error: Cannot find module 'webpack'
Require stack:
- /home/commonsadmin/commons-web-frontend/node_modules/@next/react-refresh-utils/ReactRefreshWebpackPlugin.js
- /home/commonsadmin/commons-web-frontend/node_modules/next/dist/build/webpack-config.js
- /home/commonsadmin/commons-web-frontend/node_modules/next/dist/build/index.js
- /home/commonsadmin/commons-web-frontend/node_modules/next/dist/cli/next-build.js
- /home/commonsadmin/commons-web-frontend/node_modules/next/dist/bin/next
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/commonsadmin/commons-web-frontend/node_modules/@next/react-refresh-utils/ReactRefreshWebpackPlugin.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:10557) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10557) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

本地信息 节点:v15.1.0 操作系统:macOS 11.1

服务器信息 节点:v15.1.0 操作系统:Ubuntu 20.08

我的 package.json

{
  "name": "commons-frontend",
  "version": "1.0.0",
  "description": "A social reading space at a different pace of conversation.",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "keywords": [

  ],
  "author": "tbd",
  "license": "ISC",
  "dependencies": {
    "i": "^0.3.6",
    "isomorphic-fetch": "^3.0.0",
    "js-cookie": "^2.2.1",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.24.0",
    "next": "^10.0.5",
    "npm": "^6.11.3",
    "nprogress": "^0.2.0",
    "prop-types": "^15.7.2",
    "query-string": "^6.8.3",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-google-login": "^5.0.5",
    "react-quill": "^1.3.3",
    "react-render-html": "^0.6.0",
    "reactstrap": "^8.0.1",
    "sass": "^1.32.4"
  }
}

标签: node.jsubuntuwebpacknext.js

解决方案


推荐阅读