Building an Eleventy project works locally, but fails on Netlify

So far, building my Eleventy project on Netlify using Netlify Build ended with no problems. During my last development session, I modified the .eleventy.js configuration file of my project to include an NPM package. The file, now, looks like this:

const eleventySass = require("eleventy-sass");

module.exports = function (eleventyConfig) {
   eleventyConfig.addPassthroughCopy("source/images/*")
   eleventyConfig.addPlugin(eleventySass);
   return { dir: { input: "source", output: "_site" } };
};

My package.json file looks like this:

{
  "name": "francoscarpa.com",
  "version": "1.0.0",
  "description": "This repository contains the source code of Franco Scarpa’s website, [francoscarpa.com](https://francoscarpa.com). I built it from scratch, using the [Eleventy](https://www.11ty.dev/) static site generator to help me in the process. I love the [JAMStack](https://jamstack.org/) approach to Web development, and I adopted it when building my website, which is static, super-fast, and with attention to Web accessibility.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/francoscarpa/francoscarpa.com.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/francoscarpa/francoscarpa.com/issues"
  },
  "homepage": "https://github.com/francoscarpa/francoscarpa.com#readme",
  "devDependencies": {
    "@11ty/eleventy": "^1.0.1"
  },
  "dependencies": {
    "eleventy-sass": "^1.2.1"
  }
}

Now, when I run Netlify Build, I get the following output, showing errors:

2:47:35 PM: Build ready to start
2:47:37 PM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
2:47:37 PM: build-image tag: v4.8.0
2:47:37 PM: buildbot version: 13616ca0f4280331d49967e190a04e108291d30c
2:47:37 PM: Building without cache
2:47:37 PM: Starting to prepare the repo for build
2:47:37 PM: No cached dependencies found. Cloning fresh repo
2:47:37 PM: git clone https://github.com/francoscarpa/francoscarpa.com
2:47:38 PM: Preparing Git Reference refs/heads/main
2:47:38 PM: Parsing package.json dependencies
2:47:39 PM: Starting build script
2:47:39 PM: Installing dependencies
2:47:39 PM: Python version set to 2.7
2:47:40 PM: Downloading and installing node v12.18.0...
2:47:40 PM: Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz...
2:47:40 PM: Computing checksum with sha256sum
2:47:41 PM: Checksums matched!
2:47:42 PM: Now using node v12.18.0 (npm v6.14.4)
2:47:42 PM: Started restoring cached build plugins
2:47:42 PM: Finished restoring cached build plugins
2:47:42 PM: Attempting ruby version 2.7.1, read from environment
2:47:43 PM: Required ruby-2.7.1 is not installed - installing.
2:47:44 PM: Searching for binary rubies, this might take some time.
2:47:44 PM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.7.1.tar.bz2
2:47:44 PM: Checking requirements for ubuntu.
2:47:44 PM: Requirements installation successful.
2:47:44 PM: ruby-2.7.1 - #configure
2:47:44 PM: ruby-2.7.1 - #download
2:47:45 PM: ruby-2.7.1 - #validate archive
2:47:49 PM: ruby-2.7.1 - #extract
2:47:51 PM: ruby-2.7.1 - #validate binary
2:47:51 PM: ruby-2.7.1 - #setup
2:47:52 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1@global
2:47:52 PM: ruby-2.7.1 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
2:47:52 PM: ruby-2.7.1 - #generating global wrappers........
2:47:52 PM: ruby-2.7.1 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.7.1
2:47:52 PM: ruby-2.7.1 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
2:47:53 PM: ruby-2.7.1 - #generating default wrappers........
2:47:53 PM: Using /opt/buildhome/.rvm/gems/ruby-2.7.1
2:47:53 PM: Using ruby version 2.7.1
2:47:54 PM: Using PHP version 8.0
2:47:54 PM: No npm workspaces detected
2:47:54 PM: Started restoring cached node modules
2:47:54 PM: Finished restoring cached node modules
2:47:54 PM: Installing NPM modules using NPM version 6.14.4
2:48:03 PM: npm notice created a lockfile as package-lock.json. You should commit this file.
2:48:03 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
2:48:03 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2:48:03 PM: added 329 packages from 398 contributors and audited 330 packages in 8.513s
2:48:03 PM: 26 packages are looking for funding
2:48:03 PM:   run `npm fund` for details
2:48:03 PM: found 0 vulnerabilities
2:48:03 PM: NPM modules installed
2:48:04 PM: Started restoring cached go cache
2:48:04 PM: Finished restoring cached go cache
2:48:04 PM: Installing Go version 1.14.4
2:48:08 PM: unset GOOS;
2:48:08 PM: unset GOARCH;
2:48:08 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.14.4.linux.amd64';
2:48:08 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.14.4.linux.amd64/bin:${PATH}";
2:48:08 PM: go version >&2;
2:48:08 PM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.14.4.linux.amd64.env"
2:48:08 PM: go version go1.14.4 linux/amd64
2:48:08 PM: Installing missing commands
2:48:08 PM: Verify run directory
2:48:09 PM: ​
2:48:09 PM: ────────────────────────────────────────────────────────────────
2:48:09 PM:   Netlify Build                                                 
2:48:09 PM: ────────────────────────────────────────────────────────────────
2:48:09 PM: ​
2:48:09 PM: ❯ Version
2:48:09 PM:   @netlify/build 27.1.1
2:48:09 PM: ​
2:48:09 PM: ❯ Flags
2:48:09 PM:   baseRelDir: true
2:48:09 PM:   buildId: 62863c67c81fca1f7df07ba0
2:48:09 PM:   deployId: 62863c67c81fca1f7df07ba2
2:48:09 PM: ​
2:48:09 PM: ❯ Current directory
2:48:09 PM:   /opt/build/repo
2:48:09 PM: ​
2:48:09 PM: ❯ Config file
2:48:09 PM:   No config file was defined: using default values.
2:48:09 PM: ​
2:48:09 PM: ❯ Context
2:48:09 PM:   production
2:48:09 PM: ​
2:48:09 PM: ────────────────────────────────────────────────────────────────
2:48:09 PM:   1. Build command from Netlify app                             
2:48:09 PM: ────────────────────────────────────────────────────────────────
2:48:09 PM: ​
2:48:09 PM: $ eleventy
2:48:10 PM: [11ty] Eleventy CLI Fatal Error: (more in DEBUG output)
2:48:10 PM: [11ty] 1. Error in your Eleventy config file '/opt/build/repo/.eleventy.js'. (via EleventyConfigError)
2:48:10 PM: [11ty] 2. Unexpected token '?' (via SyntaxError)
2:48:10 PM: [11ty]
2:48:10 PM: [11ty] Original error stack trace: /opt/build/repo/node_modules/eleventy-sass/lib/eleventy-sass.js:16
2:48:10 PM: [11ty]   let env = process.env.ELEVENTY_ENV ?? defaultEnv;
2:48:10 PM: [11ty]                                       ^
2:48:10 PM: [11ty]
2:48:10 PM: [11ty] SyntaxError: Unexpected token '?'
2:48:10 PM: [11ty]     at wrapSafe (internal/modules/cjs/loader.js:1054:16)
2:48:10 PM: [11ty]     at Module._compile (internal/modules/cjs/loader.js:1102:27)
2:48:10 PM: [11ty]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2:48:10 PM: [11ty]     at Module.load (internal/modules/cjs/loader.js:986:32)
2:48:10 PM: [11ty]     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2:48:10 PM: [11ty]     at Module.require (internal/modules/cjs/loader.js:1026:19)
2:48:10 PM: [11ty]     at require (internal/modules/cjs/helpers.js:72:18)
2:48:10 PM: [11ty]     at Object.<anonymous> (/opt/build/repo/node_modules/eleventy-sass/index.js:1:18)
2:48:10 PM: [11ty]     at Module._compile (internal/modules/cjs/loader.js:1138:30)
2:48:10 PM: [11ty]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2:48:10 PM: ​
2:48:10 PM: ────────────────────────────────────────────────────────────────
2:48:10 PM:   "build.command" failed                                        
2:48:10 PM: ────────────────────────────────────────────────────────────────
2:48:10 PM: ​
2:48:10 PM:   Error message
2:48:10 PM:   Command failed with exit code 1: eleventy (https://ntl.fyi/exit-code-1)
2:48:10 PM: ​
2:48:10 PM:   Error location
2:48:10 PM:   In Build command from Netlify app:
2:48:10 PM:   eleventy
2:48:10 PM: ​
2:48:10 PM:   Resolved config
2:48:10 PM:   build:
2:48:10 PM:     command: eleventy
2:48:10 PM:     commandOrigin: ui
2:48:10 PM:     publish: /opt/build/repo/_site
2:48:10 PM:     publishOrigin: ui
2:48:10 PM: Caching artifacts
2:48:10 PM: Started saving node modules
2:48:10 PM: Finished saving node modules
2:48:10 PM: Started saving build plugins
2:48:10 PM: Finished saving build plugins
2:48:10 PM: Started saving pip cache
2:48:10 PM: Finished saving pip cache
2:48:10 PM: Started saving emacs cask dependencies
2:48:10 PM: Finished saving emacs cask dependencies
2:48:10 PM: Started saving maven dependencies
2:48:10 PM: Finished saving maven dependencies
2:48:10 PM: Started saving boot dependencies
2:48:10 PM: Finished saving boot dependencies
2:48:10 PM: Started saving rust rustup cache
2:48:10 PM: Finished saving rust rustup cache
2:48:10 PM: Started saving go dependencies
2:48:11 PM: Finished saving go dependencies
2:48:13 PM: Cached ruby version 2.7.1
2:48:13 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:48:13 PM: Creating deploy upload records
2:48:13 PM: Failing build: Failed to build site
2:48:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
2:48:13 PM: Finished processing build request in 36.281825971s

I’m not able to understand what goes wrong.

You’re using Node 12. ?? syntax is not supported till Node 14, I suppose. You’d need to upgrade your Node version: