[ERROR] Top-level await is not available in the configured target environment ("node14")

I am getting an error that I’m using a feature not supported in Node v14. However, I’m not using Node v14, but v16. I have selected version 16 in every way I could find from the docs.

cat netlify.toml
[functions]
  node_bundler = "esbuild"
  external_node_modules = ["pg"]

[build.environment]
  NODE_VERSION = "16"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"

[context.production.environment]
  NODE_VERSION = "16"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"

[context.deploy-preview.environment]
  NODE_VERSION = "16"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"
cat .node-version
16

So why does it think I want Node v14 still?

Site name: majestic-kitsune-c7e613

Build logs:

1:27:20 AM: Build ready to start
1:27:22 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
1:27:22 AM: build-image tag: v4.8.0
1:27:22 AM: buildbot version: 17f6c1ab2fe6d61574ce02b038041b816bf6c085
1:27:22 AM: Fetching cached dependencies
1:27:22 AM: Failed to fetch cache, continuing with build
1:27:22 AM: Starting to prepare the repo for build
1:27:22 AM: No cached dependencies found. Cloning fresh repo
1:27:22 AM: git clone https://github.com/acarl005/sql-tutorial
1:27:23 AM: Preparing Git Reference refs/heads/netlify
1:27:23 AM: Parsing package.json dependencies
1:27:24 AM: Starting build script
1:27:25 AM: Installing dependencies
1:27:25 AM: Python version set to 2.7
1:27:25 AM: Attempting node version '16' from .node-version
1:27:25 AM: Downloading and installing node v16.15.0...
1:27:25 AM: Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz...
1:27:26 AM: Computing checksum with sha256sum
1:27:26 AM: Checksums matched!
1:27:28 AM: Now using node v16.15.0 (npm v8.5.5)
1:27:28 AM: Started restoring cached build plugins
1:27:28 AM: Finished restoring cached build plugins
1:27:28 AM: Attempting ruby version 2.7.2, read from environment
1:27:29 AM: Using ruby version 2.7.2
1:27:30 AM: Using PHP version 8.0
1:27:30 AM: No npm workspaces detected
1:27:30 AM: Started restoring cached node modules
1:27:30 AM: Finished restoring cached node modules
1:27:30 AM: Installing NPM modules using NPM version 8.5.5
1:27:37 AM: > sql-scholar@0.0.1 prepare
1:27:37 AM: > svelte-kit sync
1:27:37 AM: added 268 packages, and audited 271 packages in 7s
1:27:37 AM: 37 packages are looking for funding
1:27:37 AM:   run `npm fund` for details
1:27:37 AM: found 0 vulnerabilities
1:27:37 AM: NPM modules installed
1:27:38 AM: Started restoring cached go cache
1:27:38 AM: Finished restoring cached go cache
1:27:38 AM: go version go1.16.5 linux/amd64
1:27:38 AM: go version go1.16.5 linux/amd64
1:27:38 AM: Installing missing commands
1:27:38 AM: Verify run directory
1:27:39 AM: ​
1:27:39 AM: ────────────────────────────────────────────────────────────────
1:27:39 AM:   Netlify Build                                                 
1:27:39 AM: ────────────────────────────────────────────────────────────────
1:27:39 AM: ​
1:27:39 AM: ❯ Version
1:27:39 AM:   @netlify/build 27.1.3
1:27:39 AM: ​
1:27:39 AM: ❯ Flags
1:27:39 AM:   baseRelDir: true
1:27:39 AM:   buildId: 628c6cb8f00873000821d790
1:27:39 AM:   deployId: 628c6cb8f00873000821d792
1:27:39 AM: ​
1:27:39 AM: ❯ Current directory
1:27:39 AM:   /opt/build/repo
1:27:39 AM: ​
1:27:39 AM: ❯ Config file
1:27:39 AM:   /opt/build/repo/netlify.toml
1:27:39 AM: ​
1:27:39 AM: ❯ Context
1:27:39 AM:   production
1:27:39 AM: ​
1:27:39 AM: ────────────────────────────────────────────────────────────────
1:27:39 AM:   1. Build command from Netlify app                             
1:27:39 AM: ────────────────────────────────────────────────────────────────
1:27:39 AM: ​
1:27:39 AM: $ npm run build
1:27:39 AM: > sql-scholar@0.0.1 build
1:27:39 AM: > svelte-kit build
1:27:40 AM: vite v2.9.8 building for production...
1:27:40 AM: transforming...
1:27:42 AM: ✓ 64 modules transformed.
1:27:42 AM: rendering chunks...
1:27:42 AM: .svelte-kit/output/client/_app/manifest.json                                        3.42 KiB
1:27:42 AM: .svelte-kit/output/client/_app/pages/__error.svelte-5008239f.js                     0.96 KiB / gzip: 0.58 KiB
1:27:42 AM: .svelte-kit/output/client/_app/pages/__layout.svelte-11c5ed40.js                    9.26 KiB / gzip: 3.61 KiB
1:27:42 AM: .svelte-kit/output/client/_app/pages/index.svelte-167f27d4.js                       1.68 KiB / gzip: 0.84 KiB
1:27:42 AM: .svelte-kit/output/client/_app/pages/lessons/_slug_.svelte-595d903a.js              2.70 KiB / gzip: 1.36 KiB
1:27:42 AM: .svelte-kit/output/client/_app/start-014a08f0.js                                    23.24 KiB / gzip: 8.50 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/index-5cbb3ec5.js                             0.43 KiB / gzip: 0.30 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/preload-helper-e4860ae8.js                    0.55 KiB / gzip: 0.39 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/index-9a33ec17.js                             8.78 KiB / gzip: 3.48 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/module-progress-bc2f3833.js                   3.66 KiB / gzip: 1.33 KiB
1:27:42 AM: .svelte-kit/output/client/_app/assets/pages/index.svelte-355ae60b.css               0.42 KiB / gzip: 0.20 KiB
1:27:42 AM: .svelte-kit/output/client/_app/assets/pages/__error.svelte-4eba7b95.css             0.03 KiB / gzip: 0.05 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/codeflask.module-ec939124.js                  10.91 KiB / gzip: 3.32 KiB
1:27:42 AM: .svelte-kit/output/client/_app/pages/challenges/_slug_.svelte-dc53b4df.js           36.81 KiB / gzip: 13.16 KiB
1:27:42 AM: .svelte-kit/output/client/_app/assets/pages/lessons/_slug_.svelte-c5f939c8.css      0.41 KiB / gzip: 0.24 KiB
1:27:42 AM: .svelte-kit/output/client/_app/assets/pages/challenges/_slug_.svelte-cf59d6bc.css   2.90 KiB / gzip: 0.92 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/prism-9e4457ef.js                             10.77 KiB / gzip: 4.37 KiB
1:27:42 AM: .svelte-kit/output/client/_app/assets/pages/__layout.svelte-2b387a1e.css            10.52 KiB / gzip: 3.04 KiB
1:27:42 AM: .svelte-kit/output/client/_app/assets/EnrichedMarkdown-0b7317b1.css                 4.81 KiB / gzip: 1.26 KiB
1:27:42 AM: .svelte-kit/output/client/_app/chunks/EnrichedMarkdown-e4114ced.js                  20.27 KiB / gzip: 6.81 KiB
1:27:42 AM: vite v2.9.8 building SSR bundle for production...
1:27:42 AM: transforming...
1:27:43 AM: ✓ 70 modules transformed.
1:27:43 AM: rendering chunks...
1:27:43 AM: .svelte-kit/output/server/manifest.json                               4.19 KiB
1:27:43 AM: .svelte-kit/output/server/index.js                                    75.74 KiB
1:27:43 AM: .svelte-kit/output/server/entries/endpoints/query.js                  1.06 KiB
1:27:43 AM: .svelte-kit/output/server/entries/endpoints/challenges/_slug_.js      0.76 KiB
1:27:43 AM: .svelte-kit/output/server/entries/endpoints/lessons/_slug_.js         0.75 KiB
1:27:43 AM: .svelte-kit/output/server/entries/pages/__layout.svelte.js            8.76 KiB
1:27:43 AM: .svelte-kit/output/server/entries/pages/__error.svelte.js             0.91 KiB
1:27:43 AM: .svelte-kit/output/server/entries/pages/challenges/_slug_.svelte.js   15.04 KiB
1:27:43 AM: .svelte-kit/output/server/entries/pages/index.svelte.js               1.29 KiB
1:27:43 AM: .svelte-kit/output/server/entries/pages/lessons/_slug_.svelte.js      1.95 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/index-139ef218.js                    3.29 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/queries-4eaef322.js                  11.90 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/table-logic-29759a1c.js              3.60 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/misc-1a95841b.js                     0.44 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/_pages-e0ea4a88.js                   3.65 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/prism-9e4457ef.js                    15.61 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/prism-pgsql-879ec5c0.js              20.06 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/module-progress-54f472b2.js          6.55 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/EnrichedMarkdown-d1cda14b.js         15.75 KiB
1:27:43 AM: .svelte-kit/output/server/chunks/hooks-971a3c3c.js                    0.40 KiB
1:27:49 AM: vite v2.9.8 building for production...
1:27:49 AM: transforming...
1:27:49 AM: ✓ 2 modules transformed.
1:27:49 AM: rendering chunks...
1:27:50 AM: .svelte-kit/output/client/service-worker.js   3.13 KiB / gzip: 1.09 KiB
1:27:50 AM: Run npm run preview to preview your production build locally.
1:27:50 AM: 
1:27:50 AM: > Using @sveltejs/adapter-netlify
1:27:50 AM:   ✔ done
1:27:50 AM: ​
1:27:50 AM: (build.command completed in 10.5s)
1:27:50 AM: ​
1:27:50 AM: ────────────────────────────────────────────────────────────────
1:27:50 AM:   2. Functions bundling                                         
1:27:50 AM: ────────────────────────────────────────────────────────────────
1:27:50 AM: ​
1:27:50 AM: Packaging Functions from .netlify/functions-internal directory:
1:27:50 AM:  - render.js
1:27:50 AM: ​
1:27:50 AM: ▲ [WARNING] The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected
1:27:50 AM:     .netlify/server/chunks/prism-9e4457ef.js:244:51:
1:27:50 AM:       244 │ ...ined" && module.exports && (module.exports = Prism), typeof gl...
          ╵                                ~~~~~~
1:27:50 AM:   This file is considered to be an ECMAScript module because the enclosing "package.json" file sets the type of this file to "module":
1:27:50 AM:     package.json:3:10:
1:27:50 AM:       3 │   "type": "module",
1:27:50 AM:         ╵           ~~~~~~~~
1:27:50 AM: ✘ [ERROR] Top-level await is not available in the configured target environment ("node14")
1:27:50 AM:     .netlify/server/chunks/queries-4eaef322.js:409:0:
1:27:50 AM:       409 │ await masterClient.connect();
1:27:50 AM:           ╵ ~~~~~
1:27:50 AM: ▲ [WARNING] Ignoring this import because "node_modules/lodash-es/lodash.js" was marked as having no side effects
1:27:50 AM:     .netlify/server/entries/endpoints/query.js:9:7:
1:27:50 AM:       9 │ import "lodash-es";
1:27:50 AM:         ╵        ~~~~~~~~~~~
1:27:50 AM:   "sideEffects" is false in the enclosing "package.json" file
1:27:50 AM:     node_modules/lodash-es/package.json:14:2:
1:27:50 AM:       14 │   "sideEffects": false,
1:27:50 AM:          ╵   ~~~~~~~~~~~~~
1:27:50 AM: ▲ [WARNING] Ignoring this import because "node_modules/lodash-es/lodash.js" was marked as having no side effects
1:27:50 AM:     .netlify/server/entries/endpoints/challenges/_slug_.js:6:7:
1:27:50 AM:       6 │ import "lodash-es";
1:27:50 AM:         ╵        ~~~~~~~~~~~
1:27:50 AM:   "sideEffects" is false in the enclosing "package.json" file
1:27:50 AM:     node_modules/lodash-es/package.json:14:2:
1:27:50 AM:       14 │   "sideEffects": false,
1:27:50 AM:          ╵   ~~~~~~~~~~~~~
1:27:50 AM: ▲ [WARNING] Ignoring this import because "node_modules/lodash-es/lodash.js" was marked as having no side effects
1:27:50 AM:     .netlify/server/entries/endpoints/lessons/_slug_.js:6:7:
1:27:50 AM:       6 │ import "lodash-es";
1:27:50 AM:         ╵        ~~~~~~~~~~~
1:27:50 AM:   "sideEffects" is false in the enclosing "package.json" file
1:27:50 AM:     node_modules/lodash-es/package.json:14:2:
1:27:50 AM:       14 │   "sideEffects": false,
1:27:50 AM:          ╵   ~~~~~~~~~~~~~
1:27:51 AM: ​
1:27:51 AM: ────────────────────────────────────────────────────────────────
1:27:51 AM:   Bundling of Function "render" failed                          
1:27:51 AM: ────────────────────────────────────────────────────────────────
1:27:51 AM: ​
1:27:51 AM:   Error message
1:27:51 AM:   Build failed with 1 error:
1:27:51 AM:   .netlify/server/chunks/queries-4eaef322.js:409:0: ERROR: Top-level await is not available in the configured target environment ("node14")
1:27:51 AM: ​
1:27:51 AM:   Error location
1:27:51 AM:   While bundling Function "render"
1:27:51 AM: ​
1:27:51 AM:   Resolved config
1:27:51 AM:   build:
1:27:51 AM:     command: npm run build
1:27:51 AM:     commandOrigin: ui
1:27:51 AM:     environment:
1:27:51 AM:       - MASTER_PASSWORD
1:27:51 AM:       - MASTER_USER
1:27:51 AM:       - PGDATABASE
1:27:51 AM:       - PGHOST
1:27:51 AM:       - PGPORT
1:27:51 AM:       - STUDENT_PASSWORD
1:27:51 AM:       - STUDENT_USER
1:27:51 AM:       - NODE_VERSION
1:27:51 AM:       - AWS_LAMBDA_JS_RUNTIME
1:27:51 AM:     publish: /opt/build/repo/build
1:27:51 AM:     publishOrigin: ui
1:27:53 AM: Creating deploy upload records
1:27:51 AM:   functions:
1:27:51 AM:     '*':
1:27:51 AM:       external_node_modules:
1:27:53 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:27:51 AM:         - pg
1:27:51 AM:       node_bundler: esbuild
1:27:51 AM:   headers:
1:27:51 AM:     - for: /_app/*
      values:
        cache-control: public, immutable, max-age=31536000
  redirects:
    - from: '*'
      status: 200
      to: /.netlify/functions/render
Caching artifacts
1:27:51 AM: Started saving node modules
1:27:51 AM: Finished saving node modules
1:27:51 AM: Started saving build plugins
1:27:51 AM: Finished saving build plugins
1:27:51 AM: Started saving pip cache
1:27:51 AM: Finished saving pip cache
1:27:51 AM: Started saving emacs cask dependencies
1:27:51 AM: Finished saving emacs cask dependencies
1:27:51 AM: Started saving maven dependencies
1:27:51 AM: Finished saving maven dependencies
1:27:51 AM: Started saving boot dependencies
1:27:52 AM: Finished saving boot dependencies
1:27:52 AM: Started saving rust rustup cache
1:27:52 AM: Finished saving rust rustup cache
1:27:52 AM: Started saving go dependencies
1:27:52 AM: Finished saving go dependencies
1:27:53 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:27:53 AM: Failing build: Failed to build site
1:27:53 AM: Finished processing build request in 31.338218646s

Hi @acarl005,

Netlify Functions (AWS Lambda), still supports only Node 14 as the maximum value.

Hi @hrishikesh , thanks for the response. I see that Node v16 is only very recently supported by AWS Lambdas. Do you know if there is an estimated release date for Node v16 in Netlify functions?

I was aware that AWS was planning to launch that by mid-May, but missed the launch announcement. In any case, there’s no additional config that Netlify needs to do and you can use Node 16 by adding the following environment variable in your Netlify UI:

AWS_LAMBDA_JS_RUNTIME, value: nodejs16.x

I tried redeploying, but I’m still getting the same error. It is still trying to use Node v14.

10:48:11 PM: ────────────────────────────────────────────────────────────────
10:48:11 PM:   2. Functions bundling                                         
10:48:11 PM: ────────────────────────────────────────────────────────────────
10:48:11 PM: ​
10:48:11 PM: Packaging Functions from .netlify/functions-internal directory:
10:48:11 PM:  - render.js
10:48:11 PM: ​
10:48:11 PM: ✘ [ERROR] Top-level await is not available in the configured target environment ("node14")
10:48:11 PM:     .netlify/server/chunks/queries-80114be5.js:424:0:
10:48:11 PM:       424 │ await masterClient.connect();
10:48:11 PM:           ╵ ~~~~~

I’m pretty confident I set the config necessary to select Node v16.

I added the env variable in the Netlify UI:

Here is my netlify.toml

[functions]
  node_bundler = "esbuild"
  external_node_modules = ["pg"]

[build.environment]
  NODE_VERSION = "16"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"

[context.production.environment]
  NODE_VERSION = "16"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"

[context.deploy-preview.environment]
  NODE_VERSION = "16"
  AWS_LAMBDA_JS_RUNTIME = "nodejs16.x"

And my .node-version file

16

The site seems to be deleted. Are you still having issues?

Oops. I forgot to mention I deleted the old site and created a new one to see if that could fix the issue.

Site name: sql-scholar
Site ID: 8195a125-53d2-49e3-84fa-f4ae1c2f9259

According to your deploy logs, this error seems to be gone. Do you still need help?

Yes, I still need hep. I removed a code path to get it deployed. But the problem is still there, and I still need it to run on node v16. It last occurred on this build:

Hi @acarl005,

Could you specify what exactly it is that you removed? That could have some clues as to what’s going on.

Also, if you can share a minimal reproduction of the one with the error, we could also debug it on our end.

I created a minimal reproduction example here: Netlify App

Source code is here: GitHub - acarl005/netlify-node16

Like the original, I need node v16, yet it is trying to build for node v14 still

11:21:55 PM: ────────────────────────────────────────────────────────────────
11:21:55 PM:   2. Functions bundling                                         
11:21:55 PM: ────────────────────────────────────────────────────────────────
11:21:55 PM: ​
11:21:55 PM: Packaging Functions from .netlify/functions-internal directory:
11:21:55 PM:  - render.js
11:21:55 PM: ​
11:21:55 PM: ✘ [ERROR] Top-level await is not available in the configured target environment ("node14")
11:21:55 PM:     .netlify/server/entries/endpoints/index.js:1:13:
11:21:55 PM:       1 │ const name = await Promise.resolve("world");
11:21:55 PM:         ╵              ~~~~~
11:21:56 PM: ​
11:21:56 PM: ❯ Failed to bundle functions with selected bundler (fallback used):
11:21:56 PM:    - render.zip
11:21:56 PM: ​
11:21:56 PM: (Functions bundling completed in 755ms)

Hey @acarl005,

I’ve replied to the comment on the GitHub issue that was open: Unable to build Node v16 app on Netlify · Issue #5377 · sveltejs/kit · GitHub

and it does seem to be a problem with Netlify. We’re working on getting it fixed and would follow up as soon as we have more information (or possibly a fix).

Meanwhile, I believe you could use Promise.then() as an alternative?

You can also watch this:

1 Like