vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.22k stars 26.77k forks source link

output: "standalone" not working when using .cjs as config file extension. #38544

Open larsqa opened 2 years ago

larsqa commented 2 years ago

Verify canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000
Binaries:
  Node: 16.15.0
  npm: 8.5.5
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.2.2
  eslint-config-next: 12.1.4
  react: 18.0.0
  react-dom: 18.0.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

The option output: "standalone" in the next.config.js file is ignored when using next.config.cjs (note: .cjs) as file extension.

Expected Behavior

output: "standalone" should work in both .js and .cjs files

Link to reproduction

N/A

To Reproduce

N/A

jankaifer commented 1 year ago

repro: https://github.com/JanKaifer/next-repro-38544.git

mikew commented 9 months ago

It just doesn't look like next.config.cjs is loaded on my end:

# I'm using ESM
$ cat package.json | jq --raw-output .type
module

# Set up an intentional error in next.config
$ echo 'throw new Error("intentional error in next.config")' > next.config.cjs

# Try a build, it succeeds, signaling `next.config.cjs` is never loaded
$ ./node_modules/.bin/next build 
 ✓ Linting and checking validity of types    
   ▲ Next.js 14.0.4

 ✓ Creating an optimized production build    
 ✓ Compiled successfully
 ✓ Collecting page data    
 ✓ Generating static pages (3/3) 
 ✓ Collecting build traces    
 ✓ Finalizing page optimization    

Route (pages)                              Size     First Load JS
┌ ○ / (801 ms)                             68 kB           206 kB
├   /_app                                  0 B             138 kB
└ ○ /404                                   182 B           138 kB
+ First Load JS shared by all              138 kB
  ├ chunks/framework-5429a50ba5373c56.js   45.2 kB
  ├ chunks/main-72cd581c1e9bd837.js        31.6 kB
  ├ chunks/pages/_app-9e8e58a043cf1f7b.js  59.8 kB
  └ chunks/webpack-87b3a303122f2f0d.js     995 B

○  (Static)  prerendered as static content

# Move it to a regular .js file
$ mv next.config.cjs next.config.js
# Build correctly fails, but should have also failed previously
$ ./node_modules/.bin/next build   
 ⨯ Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error

> Build error occurred
Error: intentional error in next.config
    at file:///home/mike/Work/transmission-material-ui/next.config.js:1:7
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)