fastly / next-compute-js

Run Next.js on Fastly Compute
MIT License
75 stars 5 forks source link

New Next.js 13 project with TypeScript does not compile #14

Open egeriis opened 1 year ago

egeriis commented 1 year ago

I understand that Next.js 13 is not yet listed as officially supported. That said, this information may be helpful.

After bootstrapping a clean Next.js 13 project with TypeScript support, I was getting a lot of errors about unsupported syntax when running fastly compute serve:

✘ [ERROR] Transforming array spread to the configured target environment ("es5") is not supported yet

    bin/index.js:2:1276885:
      2 │ ...n,h=[...Array.isArray(u)?u:[u],...Array.isArray(p)?p:[p]];a.defa...
        ╵                                   ~~~

  The target environment was set to "es5" here:

    ../tsconfig.json:3:14:
      3 │     "target": "es5",
        ╵               ~~~~~

✘ [ERROR] Transforming const to the configured target environment ("es5") is not supported yet

    bin/index.js:2:1277385:
      2 │ ...vmode":void 0}))}function S(){const{docComponentsRendered:e}=a.u...
        ╵                                  ~~~~~

These errors refer to the TypeScript configuration.

After changing target to es6 in tsconfig.json, the project did compile and fastly compute serve ran without issue. However, it still wasn't possible to access the Next.js app, as I was getting 500 response and saw this message in terminal:

2023-01-12T15:08:21.860974Z  WARN no backend definitions found in /Users/ronni/Development/seatgeek/fastly-nextjs-poc/compute-js/fastly.toml
2023-01-12T15:08:21.861102Z  INFO Listening on http://127.0.0.1:7676
2023-01-12T15:08:34.983914Z  INFO request{id=0}: handling request GET http://127.0.0.1:7676/
2023-01-12T15:08:35.013234Z  INFO request{id=0}: request completed using 31.2 MB of WebAssembly heap
2023-01-12T15:08:35.013261Z  INFO request{id=0}: request completed in 29ms
Promise rejected but never handled: A.isTargetLikeServerless is not a function
Stack:
  get _isLikeServerless@<stdin>:2108:51
  getFontManifest@<stdin>:2006:26
  @<stdin>:25826:779
  D@<stdin>:1784:15
  bin/index.js/5150/getServer/<@<stdin>:2132:38
  fulfilled@<stdin>:317:26
doronaviguy commented 1 year ago

I compiled it successfully with esnext

egeriis commented 1 year ago

@doronaviguy Was the service accessible? As noted, it was possible to compile it after changing the target, however, the app did not run correctly when I tried.