Cannot find module 'styled-jsx/package.json

PLEASE help us help you by writing a good post!

  • SiteID: 800b2abf-4890-4c7f-92ed-3404f8cad0cd

netlify.toml file:

[[plugins]]
package = "@netlify/plugin-nextjs"

[build]
command = "turbo run build --filter platform"
publish = "/.next"
base = "apps/platform"

[dev]
command = "turbo run dev --filter platform"
publish = "/.next"
base = "apps/platform"

[functions]
included_files = [
    "../../node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/router-context*",
    "../../node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/amp-context*",
    "../../node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context*",
    ".env"
]

Since the 12th of September at 9:22am BST all of our deploy previews and deploys have been failing with the following error:

error decoding lambda response: error decoding lambda response: unexpected end of JSON input

Upon looking at the SSR functions we see the following error:

Sep 16, 04:47:25 PM: 748387c7 ERROR  Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Cannot find module 'styled-jsx/package.json'\nRequire stack:\n- /var/task/node_modules/next/dist/server/require-hook.js\n- /var/task/node_modules/next/dist/server/next.js\n- /var/task/node_modules/next/dist/server/lib/start-server.js\n- /var/task/apps/platform/.netlify/dist/run/next.cjs","reason":{"errorType":"Error","errorMessage":"Cannot find module 'styled-jsx/package.json'\nRequire stack:\n- /var/task/node_modules/next/dist/server/require-hook.js\n- /var/task/node_modules/next/dist/server/next.js\n- /var/task/node_modules/next/dist/server/lib/start-server.js\n- /var/task/apps/platform/.netlify/dist/run/next.cjs","code":"MODULE_NOT_FOUND","requireStack":["/var/task/node_modules/next/dist/server/require-hook.js","/var/task/node_modules/next/dist/server/next.js","/var/task/node_modules/next/dist/server/lib/start-server.js","/var/task/apps/platform/.netlify/dist/run/next.cjs"],"stack":["Error: Cannot find module 'styled-jsx/package.json'","Require stack:","- /var/task/node_modules/next/dist/server/require-hook.js","- /var/task/node_modules/next/dist/server/next.js","- /var/task/node_modules/next/dist/server/lib/start-server.js","- /var/task/apps/platform/.netlify/dist/run/next.cjs","    at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)","    at resolve (node:internal/modules/helpers:188:19)","    at Object.<anonymous> (/var/task/node_modules/next/dist/server/require-hook.js:38:32)","    at Module._compile (node:internal/modules/cjs/loader:1364:14)","    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)","    at Module.load (node:internal/modules/cjs/loader:1203:32)","    at Module._load (node:internal/modules/cjs/loader:1019:12)","    at Module.require (node:internal/modules/cjs/loader:1231:19)","    at require (node:internal/modules/helpers:177:18)","    at Object.<anonymous> (/var/task/node_modules/next/dist/server/next.js:25:1)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Cannot find module 'styled-jsx/package.json'","Require stack:","- /var/task/node_modules/next/dist/server/require-hook.js","- /var/task/node_modules/next/dist/server/next.js","- /var/task/node_modules/next/dist/server/lib/start-server.js","- /var/task/apps/platform/.netlify/dist/run/next.cjs","    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)","    at process.emit (node:events:517:28)","    at emit (node:internal/process/promises:149:20)","    at processPromiseRejections (node:internal/process/promises:283:27)","    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}Sep 16, 04:47:25 PM: 748387c7 ERROR  Unknown application error occurredSep 16, 04:47:25 PM: 748387c7 ERROR  Runtime.Unknown

This seems to have happened out of nowhere as I cannot see in the git history any package changes that would introduce this have tested with the following configurations:

"netlify/cli": "17.23.5"
"@netlify/plugin-nextjs": "5.4.0" | "5.7.1" | "4.22.0"
 "next": "14.2.3"

Note that if I run Netlify locally using netlify dev the app works as expected.

Can anyone shine a light on this issue? I have seen similar reports on the forum but all seem to say that the upgrade with next 13 and plugin-nextjs v5 should fix but it does not seem to be working for us.

Your settings should be:

Base: unset
Package: apps/platform
Publish: apps/platform/.next

Set all this in Netlify UI and remove the settings from the toml. Don’t forget to skip Turbo cache.