fastly / next-compute-js

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

Using TypeScript appears to require target to be esnext #15

Open egeriis opened 1 year ago

egeriis commented 1 year ago

With a freshly created Next.js app (using create-next-app) with TypeScript support, errors are occurring when running fastly compute serve as the transpilation step does not support certain features to be transpiled to es5. es5 is the default target for a new Next.js app with TypeScript support.

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

    bin/index.js:2:1265012:
      2 │ ... n.default.Component{render(){const{statusCode:e,withDarkMode:t=...
        ╵                                  ~~~~~

  The target environment was set to "es5" here:

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

Even with target set to es6, an error is occurring:

Error: Build failed with 1 error:
bin/index.js:2:1070811: ERROR: Transforming async generator functions to the configured target environment ("es6") is not supported yet

I was able to resolve this issue by configuring TypeScript to target esnext:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

It would be helpful to add a small note to the instruction about TypeScript support.

zialh commented 1 year ago

ES2018 was the oldest possible version that works for me, apart from ESNext, you might want to opt to it to be as compatible as possible with older environments