vercel / next.js

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

`target: 'serverless'` results in `Syntax error: Unexpected token` #26542

Closed VinSpee closed 2 years ago

VinSpee commented 3 years ago

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

14.17.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

netlify

Describe the Bug

Hi!

I am attempting to deploy via Netlify. Their config recommends target: 'serverless' in my next.config.js. Setting this value results in this build error:

info  - Creating an optimized production build  
Failed to compile.

.next/build-manifest.json:2:17
Syntax error: Unexpected token, expected ";"

  1 | {
> 2 |   "polyfillFiles": [
    |                  ^
  3 |     "static/chunks/polyfills-fe03425c607e25a05075.js"
  4 |   ],
  5 |   "devFiles": [],

If i disabled target: 'serverless', I can build just fine:

info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
info  - Generating static pages (4/4)
info  - Finalizing page optimization  

Page                             Size     First Load JS
┌ ○ /                            1.15 kB        1.75 MB
├   /_app                        0 B            1.73 MB
├ ○ /404                         3.1 kB         1.74 MB
├ λ /api/auth/[...auth0]         0 B            1.73 MB
├ λ /api/auth/token              0 B            1.73 MB
├ λ /protect                     12.2 kB        1.75 MB
└ ○ /workflows                   1.19 kB        1.75 MB
+ First Load JS shared by all    1.73 MB
  ├ chunks/framework.f076ac.js   42.4 kB
  ├ chunks/main.f170e6.js        24.2 kB
  ├ chunks/pages/_app.06e6a7.js  1.67 MB
  └ chunks/webpack.d6ded2.js     965 B

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
   (ISR)     incremental static regeneration (uses revalidate in getStaticProps)

I have tried disabling webpack5, and have tried the latest canary builds (up to 11.0.1-canary.8)

Expected Behavior

the build to succeed, or provide a more useful error message in the case of a real error.

To Reproduce

next.config.js

module.exports = withPlugins([
  withTM(),
  withCSVLoader(),
  withConditionals(),
  {
    target: 'serverless',
    images: {
      domains: ['you.s3.amazonaws.com'],
    },
    async rewrites() {
      return [
        {
          // Proxy API requests
          source: '/api/:slug*',
          destination: `${process.env.NEXT_PUBLIC_APP_API_URL}/1/:slug*`,
        },
      ];
    },
  },
]);

> next build

davidcalhoun commented 3 years ago

It's not well documented, but serverless has issues. Did you try instead using experimental-serverless-trace?

More context: https://github.com/vercel/next.js/issues/20487#issuecomment-753884085

balazsorban44 commented 2 years ago

target is now deprecated. https://nextjs.org/blog/next-12#output-file-tracing

balazsorban44 commented 2 years ago

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.