我正在开发一个与NextJs和ReactJs一起开发的项目。突然,这个项目显示分配失败-JavaScript堆内存不足问题。我已经在线尝试了所有资源,但是这些资源对我不起作用。我认为,next.config.js或webpack中可能发生了一些错误,但是我不确定。
package.json
{
"name": "personal-blog",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-brands-svg-icons": "^5.13.0",
"@fortawesome/free-regular-svg-icons": "^5.13.0",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/react-fontawesome": "^0.1.9",
"bootstrap": "^4.4.1",
"dotenv": "^8.2.0",
"isomorphic-unfetch": "^3.0.0",
"moment": "^2.24.0",
"next": "9.3.5",
"node-fetch": "^2.6.0",
"react": "16.13.1",
"react-bootstrap": "^1.0.1",
"react-debounce-input": "^3.2.2",
"react-dom": "16.13.1",
"react-moment": "^0.9.7"
},
"devDependencies": {
"sass": "^1.26.5"
}
}
next.config.js
const webpack = require("webpack");
require("dotenv").config();
module.exports = {
webpack: config => {
config.node = {
fs: 'empty'
}
const env = Object.keys(process.env).reduce((acc, curr) => {
acc[`process.env.${curr}`] = JSON.stringify(process.env[curr]);
return acc;
}, {});
config.plugins.push(new webpack.DefinePlugin(env));
return config
}
}
可视代码终端错误
<--- Last few GCs --->
[4562:0x103e3b000] 161295 ms: Mark-sweep 2041.6 (2051.3) -> 2040.7 (2051.3) MB, 3551.0 / 0.0 ms (average mu = 0.370, current mu = 0.462) allocation failure scavenge might not succeed
[4562:0x103e3b000] 170945 ms: Mark-sweep 2041.8 (2051.5) -> 2041.2 (2051.5) MB, 8225.9 / 0.2 ms (average mu = 0.253, current mu = 0.148) allocation failure GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x10072e699]
Security context: 0x3ecf281008a1 <JSObject>
1: createElement(aka createElement) [0x3ecf3bee16f9] [/Users/pater/Desktop/personal-blog/node_modules/react/cjs/react.development.js:~727] [pc=0x1d716fb9bc21](this=0x3ecfe42004a9 <undefined>,0x3ecffb609dc1 <String[#3]: div>,0x3ecfe4f40389 <Object map = 0x3ecfdd48e531>,0x3ecfe42004a9 <undefined>)
2: arguments adaptor frame: 2->3
3: createElement...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20200424.120915.4562.0.001.json
Node.js report completed
1: 0x100b6a52a node::Abort() (.cold.1) [/usr/local/bin/node]
2: 0x100081f70 node::FatalError(char const*, char const*) [/usr/local/bin/node]
3: 0x100082098 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
4: 0x10017461d v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
5: 0x1001745c7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
6: 0x10028a569 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
7: 0x10028b8ee v8::internal::Heap::MarkCompactPrologue() [/usr/local/bin/node]
8: 0x1002894eb v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
9: 0x100287f93 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
10: 0x10028f6da v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x10028fbd0 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
12: 0x10026d8c6 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType) [/usr/local/bin/node]
13: 0x1004bc90e v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
14: 0x10072e699 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
15: 0x1d716fb9bc21
Abort