Next.js: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement in IOS 9.x.

Created on 27 Apr 2019  ·  12Comments  ·  Source: vercel/next.js

Bug report

Describe the bug

SyntaxError: Strict mode does not allow function declarations in a lexically nested statement in IOS 9.x.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. install next.js 8.1.0
  2. build and start server
  3. open page in ios8 or ios9 safari
  4. See error

Expected behavior

page should work.

Screenshots

image

image

System information

  • OS: ios8, ios9
  • Browser: safari
  • Version of Next.js: 8.1.0
bug needs investigation

Most helpful comment

It also happens to me in 2 different applications using [email protected]. Had to downgrade them to make it work.

All 12 comments

@yanghuabei some problem with you,8.0.3 is well

Also in IE10

It also happens to me in 2 different applications using [email protected]. Had to downgrade them to make it work.

It also happens to me

  • Version of Next.js: 8.1.0

I can confirm that this is fixed in the latest, 8.1.1-canary.28, and probably since canary 20.

7014 removed putting async-to-promises around the Next.js client code.

As @fionawhim mentioned, this was fixed when we made async-to-promises experimental and is no longer enabled by default. I'm going to close this now, if you are still having trouble with this on the latest canary please reply with additional details.

This is actually _not_ caused by async-to-promises. It's caused by Terser defaulting to the inline=3 setting, which is inlining functions where it is unsafe to do so. It can also cause performance issues.

@ijjk Is there any backport of this fix (or another way to enable it) on the stable 8.1.0 branch? We're seeing lots of this in production logs.

Published as 8.1.1-canary.51. 🙏

after updating to 8.1.1 - canary custom ts-node (from examples folder) config went down. "Next.js now provides ts support from scratch"... How to run own custom server with typescript now?

emmm, I think it is no related to terser.
In v8.1.0, I can fixed it by adding

if (!isServer) {
      // console.log(JSON.stringify(config));
      config.module.rules.push({
        test: /\.(tsx|ts|js|mjs|jsx)$/,
        include: [
          /next-server[\\/]dist[\\/]lib/,
          /next[\\/]dist[\\/]client/,
          /next[\\/]dist[\\/]pages/,
          /[\\/](strip-ansi|ansi-regex)[\\/]/,
        ],
        exclude: path => {
          if (
            /next-server[\\/]dist[\\/]lib/.test(path) ||
            /next[\\/]dist[\\/]client/.test(path) ||
            /next[\\/]dist[\\/]pages/.test(path) ||
            /[\\/](strip-ansi|ansi-regex)[\\/]/.test(path)
          ) {
            return false;
          }
          return /node_modules/.test(path);
        },
        use: defaultLoaders.babel,
      });
    }

to file next.config.js after review the code of #7014

Was this page helpful?
0 / 5 - 0 ratings