next.js: After restarting project and open in browser console throws errors
Bug report
Describe the bug
I’m run the project on live-server, doing all by this instruction. In first runnig by command npm run start all correct, but if i restart the server i have next error:
TypeError: a.removeHeader is not a function
at SendStream.removeContentHeaderFields (/home/dzi/website/node_modules/next/dist/compiled/send/index.js:1:5160)
at SendStream.notModified (/home/dzi/website/node_modules/next/dist/compiled/send/index.js:1:5273)
at SendStream.send (/home/dzi/website/node_modules/next/dist/compiled/send/index.js:1:7976)
at onstat (/home/dzi/website/node_modules/next/dist/compiled/send/index.js:1:8914)
at FSReqCallback.oncomplete (fs.js:184:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nexjs-format-app@0.0.1 start: `next start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nexjs-format-app@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
npm installnpm run buildnpm run startctrl+cnpm run start- open in browser Video
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli '/usr/bin/node',
1 verbose cli '/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js',
1 verbose cli 'start'
1 verbose cli ]
2 info using npm@6.14.8
3 info using node@v14.15.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle nexjs-format-app@0.0.1~prestart: nexjs-format-app@0.0.1
6 info lifecycle nexjs-format-app@0.0.1~start: nexjs-format-app@0.0.1
7 verbose lifecycle nexjs-format-app@0.0.1~start: unsafe-perm in lifecycle true
8 verbose lifecycle nexjs-format-app@0.0.1~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/dzi/website/node_modules/.bin:/usr/local>
9 verbose lifecycle nexjs-format-app@0.0.1~start: CWD: /home/dzi/website
10 silly lifecycle nexjs-format-app@0.0.1~start: Args: [ '-c', 'next start' ]
11 silly lifecycle nexjs-format-app@0.0.1~start: Returned: code: 1 signal: null
12 info lifecycle nexjs-format-app@0.0.1~start: Failed to exec start script
13 verbose stack Error: nexjs-format-app@0.0.1 start: `next start`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/lib/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> (/usr/lib/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 nexjs-format-app@0.0.1
15 verbose cwd /home/dzi/website
16 verbose Linux 5.4.0-26-generic
17 verbose argv "/usr/bin/node" "/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js" "start"
18 verbose node v14.15.1
19 verbose npm v6.14.8
20 error code ELIFECYCLE
21 error errno 1
22 error nexjs-format-app@0.0.1 start: `next start`
22 error Exit status 1
23 error Failed at the nexjs-format-app@0.0.1 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Expected behavior
First start is correct but if restart projext have a problem
System information
- OS: [ Ubuntu 20.04 x64, 1 core, 1GB RAM]
- Version of Next.js: [e.g. 10.0.1]
- Version of Node.js: [e.g. 14.15.1] Git repository
{
"name": "nexjs-format-app",
"version": "0.0.1",
"description": "Online market TM Format",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"keywords": [
"market",
"format"
],
"author": "Dzi",
"license": "ISC",
"dependencies": {
"bootstrap": "^4.5.3",
"cross-env": "^7.0.2",
"firebase": "^8.0.2",
"next": "^10.0.1",
"react": "^16.8.0",
"react-bootstrap": "^1.4.0",
"react-dom": "^16.8.0",
"react-icons": "^3.11.0",
"react-redux": "^7.2.2",
"redux": "^4.0.5"
}
}
module.exports = {
trailingSlash: true,
distDir: 'build'
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 28 (5 by maintainers)
Commits related to this issue
- Add missing `removeHeader()` function to image optimizer mock res (#27763) - Related to #27724 - Related to #19309 - Related to #23140 — committed to vercel/next.js by styfle 3 years ago
- Add missing `removeHeader()` function to image optimizer mock res (#27763) - Related to #27724 - Related to #19309 - Related to #23140 — committed to blitz-js/next.js by styfle 3 years ago
Sorry I didnt share the file yet as it depends on the version of next installed.
node_modulesand change the filenode_modules/next/dist/compiled/send/index.js(I reformatted it), look for the call toremoveHeader, and wrap it in an additional if statement as seen below:becomes:
yarn patch-package package-nameornpx patch-package package-nameand patch-package will auto generate the patch file in the folder./patches../patchesfolder into the Docker container before you run npm install (the tool actually gives you a nice output).I did not share my patchfile yet as the filename is different per version of installed next. For me this was 10.2.3, thus the file name is
./patches/next+10.2.3.patchfor me. You can also adjust the filename and skip the edit of your node_modules, but you need patch-package installed. shoutout to @ds300 for this cool package, thanks!My `./patches/next+10.2.3.patch`
I just opened an issue for that and if you dig into code I linked you can see that there’s a case where object reference that should have a
removeHeadermethod will be always undefined.@timneutkens Please reopen the issue and add the patch in nextjs. Thanks to @CanKattwinkel we have found a temporary fix. It’s causing production to go down which is a very big issue and cannot be ignored.
@alula appreciate you looking into this!
I managed to fix it for me by wrapping the call with an additional if check using this patch-approach. In case anyone is hit in production out of the blue and needs an immediate hacky fix. 😉
File is
node_modules/next/dist/compiled/send/index.js@dev try next/Image components, and sounds like this. i am using next/image and src=“./svg.svg” after visite http://h/_next/image?url=%2Fimages%2Fempty.svg&w=640&q=75, my website crashed with logs.
I find the problem. It’s happend with Image component. As i understand optimizer cache live 60 sec, and after that it’s try to reoptimize image and crash. How can i change cache live of optimized images?
Thanks for reply @CanKattwinkel. I’ll have a look on that. But for now I just fixed this issue by changed the image thats served from /public to just normal html img tag as what @danjebs has mentioned on the earlier post. Thanks @danjebs also!