Next.js Discord

Discord Forum

NextJS 14.x Standalone - Azure AppService - server.js corrupted

Answered
Filipino Venus posted this in #help-forum
Open in Discord
Filipino VenusOP
Hello,
TLDR:
* using an older version of server.js works (was build on a linux agent / was before mjs file)
* using the one generated by standalone build fails

I've been trying to deploy a Standalone build of NextJs 14.x
* Target Infra: Azure AppService Windows
* packages.json > engines> node: ">= 20.17.0"
* Build agent: NodeJS 20.17.0 (via .nvmrc) + tried Windows / Linux
* Azure AppService: Node ~20 (via env var and checked via node -v in remote shell)
* Tried next.config.js or .mjs same error

the build seems to be fine i'm properly doing:
"build": "next build && cp -r .next/static .next/standalone/.next/; cp -r public .next/standalone/",

I'm deploying using WebConfigParameters: '-Handler iisnode -NodeStartFile server.js -appType node'
which properly generate the web.config with iisnode pointing to server.js

RESULT:
ERROR 500.1001 or 500.1002 on "could not find the file ... blalbabla"

though ... after using another server.js from a linux build this works with literally (nearly) literally 0 change
I'm diffed both server.js and here's what I found:
1: the const nextConfig now have all Key as string and not as JSON like before
1.1: all string are now using " and not ' anymore
2: there's no more ; at the end ... should not matter
3: the one working was before we changed from next.config.js to next.config.mjs but after rolling back to .js the result is still KO

here's the mjs file:
import path from 'path';

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
  sassOptions: {
    includePaths: [path.join(import.meta.dirname, 'styles')],
  },
};

export default nextConfig;
Answered by Filipino Venus
this is in fact a critical bug explained here:
#[standalone] Next 14.x broke namedpipe usage entirely
View full answer

5 Replies

Filipino VenusOP
ok so apparemently I had to sed / string replace the server.js:
- const currentPort = parseInt(process.env.PORT, 10) || 3000
+ const currentPort = process.env.PORT || 3000

+ add PORT to .env
this is completly insane
anybody knows why this would/could happen ?
Filipino VenusOP
this is in fact a critical bug explained here:
#[standalone] Next 14.x broke namedpipe usage entirely
Answer