首页 > 解决方案 > 构建 Next.JS 项目时出现愚蠢的生命周期错误

问题描述

我最近开始学习 Next/React 来制作个人网站,我正在尝试使用 Next.JS 构建一个网站,该网站在运行时看起来和工作正常npm run dev,但是,当我尝试构建时它给了我一个错误其中。我真的不明白这个错误,更不用说如何修复它了。

谢谢

终端日志

> portfolio@ build C:\Users\Simon\Desktop\@Documents\@@Projects\Coding\@web\portfolio
> next build

info  - Checking validity of types

./pages/blog/[slug].js
26:17  Warning: Do not include stylesheets manually. See: https://nextjs.org/docs/messages/no-css-tags.  @next/next/no-css-tags

./pages/index.js
12:9  Warning: Do not include stylesheets manually. See: https://nextjs.org/docs/messages/no-css-tags.  @next/next/no-css-tags
13:9  Warning: External synchronous scripts are forbidden. See: https://nextjs.org/docs/messages/no-sync-scripts.  @next/next/no-sync-scripts
23:13  Warning: Do not use <img>. Use Image from 'next/image' instead. See https://nextjs.org/docs/messages/no-img-element.  @next/next/no-img-element

./components/MDXComponents.js
4:1  Warning: Assign object to a variable before exporting as module default  import/no-anonymous-default-export

info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
info  - Creating an optimized production build ...events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, open 'C:\Users\Simon\Desktop\@Documents\@@Projects\Coding\@web\portfolio\.next\trace'
Emitted 'error' event on WriteStream instance at:
    at C:\Users\Simon\Desktop\@Documents\@@Projects\Coding\@web\portfolio\node_modules\next\dist\compiled\@vercel\nft\index.js:1:287421
    at C:\Users\Simon\Desktop\@Documents\@@Projects\Coding\@web\portfolio\node_modules\next\dist\compiled\@vercel\nft\index.js:1:287860
    at FSReqCallback.oncomplete (fs.js:171:23) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'open',
  path: 'C:\\Users\\Simon\\Desktop\\@Documents\\@@Projects\\Coding\\@web\\portfolio\\.next\\trace'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! portfolio@ build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the portfolio@ 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!     C:\Users\Simon\AppData\Roaming\npm-cache\_logs\2021-11-13T12_14_00_615Z-debug.log

日志文件

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Users\\Simon\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Simon\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using npm@6.14.12
3 info using node@v14.16.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle portfolio@~prebuild: portfolio@
6 info lifecycle portfolio@~build: portfolio@
7 verbose lifecycle portfolio@~build: unsafe-perm in lifecycle true
8 verbose lifecycle portfolio@~build: PATH: // Path stuff //
9 verbose lifecycle portfolio@~build: CWD: C:\Users\Simon\Desktop\@Documents\@@Projects\Coding\@web\portfolio
10 silly lifecycle portfolio@~build: Args: [ '/d /s /c', 'next build' ]
11 silly lifecycle portfolio@~build: Returned: code: 1  signal: null
12 info lifecycle portfolio@~build: Failed to exec build script
13 verbose stack Error: portfolio@ build: `next build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\Simon\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\Simon\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1048:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid portfolio@
15 verbose cwd C:\Users\Simon\Desktop\@Documents\@@Projects\Coding\@web\portfolio
16 verbose Windows_NT 10.0.19043
17 verbose argv "C:\\Users\\Simon\\nodejs\\node.exe" "C:\\Users\\Simon\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v14.16.1
19 verbose npm  v6.14.12
20 error code ELIFECYCLE
21 error errno 1
22 error portfolio@ build: `next build`
22 error Exit status 1
23 error Failed at the portfolio@ build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

.eslintrc.json

{
  "extends": "next"
}
**package.json**
{
  "name": "portfolio",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.36",
    "@fortawesome/free-brands-svg-icons": "^5.15.4",
    "@fortawesome/free-solid-svg-icons": "^5.15.4",
    "@fortawesome/react-fontawesome": "^0.1.16",
    "date-fns": "^2.25.0",
    "gray-matter": "^4.0.3",
    "next": "12.0.3",
    "next-mdx-remote": "^3.0.8",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "sass": "^1.43.4"
  },
  "devDependencies": {
    "eslint": "7.32.0",
    "eslint-config-next": "12.0.3"
  }
}

标签: node.jsreactjsnpmbuildnext.js

解决方案


推荐阅读