Build error on API function with rebuild

My site build seems to work locally but not on Netlify. Is the error at the end of the log below coming from the Netlify next plugin?

I’m not sure if this is a problem with my location of my util folder, or my config for functions in my Netlify.toml, or what. Any ideas?
The full site code is at: GitHub - ivanoats/nextweather: Weather station data focused on wind and tide for human powered watercraft

https://nextweather.netlify.app/

11:32:57 AM: Build ready to start
11:32:58 AM: build-image version: be42e453d6c8f171cc2f654acc29c0a8b60e6d93
11:32:58 AM: build-image tag: v3.7.1
11:32:58 AM: buildbot version: 7bdd3b07036ec50a4d44b86fbdc90f52d3e07727
11:32:58 AM: Fetching cached dependencies
11:32:59 AM: Starting to download cache of 1.0GB
11:33:06 AM: Finished downloading cache in 7.233829913s
11:33:06 AM: Starting to extract cache
11:33:47 AM: Finished extracting cache in 41.361791255s
11:33:48 AM: Finished fetching cache in 49.100605268s
11:33:48 AM: Starting to prepare the repo for build
11:33:48 AM: Preparing Git Reference refs/heads/main
11:33:50 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: β€˜Users/ivan/dev/nextweather/out_publish’ versus β€˜/Users/ivan/dev/nextweather/out_publish’ in the Netlify UI
11:33:50 AM: Different functions path detected, going to use the one specified in the Netlify configuration file: β€˜pages/api’ versus β€˜β€™ in the Netlify UI
11:33:51 AM: Starting build script
11:33:51 AM: Installing dependencies
11:33:51 AM: Python version set to 2.7
11:33:51 AM: Started restoring cached node version
11:33:54 AM: Finished restoring cached node version
11:33:55 AM: v12.18.0 is already installed.
11:33:56 AM: Now using node v12.18.0 (npm v6.14.4)
11:33:56 AM: Started restoring cached build plugins
11:33:56 AM: Finished restoring cached build plugins
11:33:56 AM: Attempting ruby version 2.7.1, read from environment
11:33:58 AM: Using ruby version 2.7.1
11:33:58 AM: Using PHP version 5.6
11:33:58 AM: Started restoring cached node modules
11:33:58 AM: Finished restoring cached node modules
11:33:58 AM: Installing NPM modules using NPM version 6.14.4
11:34:08 AM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I’ll try to do my best with it!npm WARN acorn-export-ns-from@0.1.0 requires a peer of acorn@^6.0.1 but none is installed. You must install peer dependencies yourself.
11:34:08 AM: npm WARN react-native-get-random-values@1.6.0 requires a peer of react-native@>=0.56 but none is installed. You must install peer dependencies yourself.
11:34:08 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
11:34:08 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {β€œos”:β€œdarwin”,β€œarch”:β€œany”} (current: {β€œos”:β€œlinux”,β€œarch”:β€œx64”})
11:34:08 AM: added 5 packages from 30 contributors and audited 1038 packages in 9.022s
11:34:09 AM: 68 packages are looking for funding
11:34:09 AM: run npm fund for details
11:34:09 AM: found 0 vulnerabilities
11:34:09 AM: NPM modules installed
11:34:09 AM: Started restoring cached go cache
11:34:09 AM: Finished restoring cached go cache
11:34:09 AM: go version go1.14.4 linux/amd64
11:34:09 AM: go version go1.14.4 linux/amd64
11:34:09 AM: Installing missing commands
11:34:09 AM: Verify run directory
11:34:11 AM: ​
11:34:11 AM: ────────────────────────────────────────────────────────────────
11:34:11 AM: Netlify Build
11:34:11 AM: ────────────────────────────────────────────────────────────────
11:34:11 AM: ​
11:34:11 AM: ❯ Version
11:34:11 AM: @netlify/build 10.2.2
11:34:11 AM: ​
11:34:11 AM: ❯ Flags
11:34:11 AM: deployId: 606a06581e1955000748f9c2
11:34:11 AM: ​
11:34:11 AM: ❯ Current directory
11:34:11 AM: /opt/build/repo
11:34:11 AM: ​
11:34:11 AM: ❯ Config file
11:34:11 AM: /opt/build/repo/netlify.toml
11:34:11 AM: ​
11:34:11 AM: ❯ Context
11:34:11 AM: production
11:34:11 AM: ​
11:34:11 AM: ❯ Loading plugins
11:34:11 AM: - @netlify/plugin-nextjs@3.0.3 from netlify.toml and package.json
11:34:11 AM: ​
11:34:11 AM: ────────────────────────────────────────────────────────────────
11:34:11 AM: 1. onPreBuild command from @netlify/plugin-nextjs
11:34:11 AM: ────────────────────────────────────────────────────────────────
11:34:11 AM: ​
11:34:12 AM: info - Using webpack 5. Reason: future.webpack5 option enabled webpack5 | Next.js
11:34:12 AM: ​
11:34:12 AM: (@netlify/plugin-nextjs onPreBuild completed in 988ms)
11:34:12 AM: ​
11:34:12 AM: ────────────────────────────────────────────────────────────────
11:34:12 AM: 2. build.command from netlify.toml
11:34:12 AM: ────────────────────────────────────────────────────────────────
11:34:12 AM: ​
11:34:12 AM: $ npm run build
11:34:13 AM: > nextweather@0.1.0 build /opt/build/repo
11:34:13 AM: > next build
11:34:14 AM: info - Using webpack 5. Reason: future.webpack5 option enabled webpack5 | Next.js
11:34:15 AM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
11:34:15 AM: info - Checking validity of types…
11:34:18 AM: info - Creating an optimized production build…
11:34:32 AM: [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can’t resolve β€˜fsevents’ in β€˜/opt/build/repo/node_modules/chokidar’ while resolving β€˜fsevents’ in /opt/build/repo/node_modules/chokidar to a directory
11:34:35 AM: (node:1394) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
11:34:36 AM: [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Can’t resolve β€˜fsevents’ in β€˜/opt/build/repo/node_modules/chokidar’ while resolving β€˜fsevents’ in /opt/build/repo/node_modules/chokidar to a directory
11:34:36 AM: warn - Compiled with warnings
11:34:36 AM: ./node_modules/keyv/src/index.js
11:34:36 AM: Critical dependency: the request of a dependency is an expression
11:34:36 AM: ./node_modules/next/dist/next-server/server/load-components.js
11:34:36 AM: Critical dependency: the request of a dependency is an expression
11:34:36 AM: ./node_modules/next/dist/next-server/server/load-components.js
11:34:36 AM: Critical dependency: the request of a dependency is an expression
11:34:36 AM: ./node_modules/next/dist/next-server/server/require.js
11:34:36 AM: Critical dependency: the request of a dependency is an expression
11:34:36 AM: ./node_modules/next/dist/next-server/server/require.js
11:34:36 AM: Critical dependency: the request of a dependency is an expression
11:34:36 AM: ./node_modules/next/dist/next-server/server/require.js
11:34:36 AM: Critical dependency: the request of a dependency is an expression
11:34:36 AM: info - Collecting page data…
11:34:37 AM: info - Generating static pages (0/3)
11:34:38 AM: info - Generating static pages (3/3)
11:34:38 AM: info - Finalizing page optimization…
11:34:38 AM: Page Size First Load JS
11:34:38 AM: β”Œ β—‹ / 3.44 kB 67.5 kB
11:34:38 AM: β”œ β”” css/9a0e57cc520cbbcc7d30.css 669 B
11:34:38 AM: β”œ /_app 0 B 64.1 kB
11:34:38 AM: β”œ β—‹ /404 3.44 kB 67.5 kB
11:34:38 AM: β”œ Ξ» /api/csv 0 B 64.1 kB
11:34:38 AM: β”œ Ξ» /api/observations 0 B 64.1 kB
11:34:38 AM: β”œ Ξ» /api/tsv 0 B 64.1 kB
11:34:38 AM: β”” Ξ» /api/util/convert 0 B 64.1 kB
11:34:38 AM: + First Load JS shared by all 64.1 kB
11:34:38 AM: β”œ chunks/597.b0deca.js 13.3 kB
11:34:38 AM: β”œ chunks/778.7db2cf.js 7.05 kB
11:34:38 AM: β”œ chunks/framework.dad012.js 42 kB
11:34:38 AM: β”œ chunks/main.9ca82e.js 151 B
11:34:38 AM: β”œ chunks/pages/_app.65838e.js 564 B
11:34:38 AM: β”œ chunks/webpack.37bb74.js 993 B
11:34:38 AM: β”” css/9555fbe4118c83c59ab9.css 203 B
11:34:38 AM: Ξ» (Lambda) server-side renders at runtime (uses getInitialProps or getServerSideProps)
11:34:38 AM: β—‹ (Static) automatically rendered as static HTML (uses no initial props)
11:34:38 AM: ● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
11:34:38 AM: (ISR) incremental static regeneration (uses revalidate in getStaticProps)
11:34:38 AM: ​
11:34:38 AM: (build.command completed in 25.6s)
11:34:38 AM: ​
11:34:38 AM: ────────────────────────────────────────────────────────────────
11:34:38 AM: 3. onBuild command from @netlify/plugin-nextjs
11:34:38 AM: ────────────────────────────────────────────────────────────────
11:34:38 AM: ​
11:34:38 AM: ** Running Next on Netlify package **
11:34:38 AM: :rocket: Next on Netlify :rocket:
11:34:38 AM: :earth_africa: Copying public/ folder to Users/ivan/dev/nextweather/out_publish
11:34:39 AM: info - Using webpack 5. Reason: future.webpack5 option enabled webpack5 | Next.js
11:34:39 AM: :briefcase: Copying static NextJS assets to Users/ivan/dev/nextweather/out_publish
11:34:39 AM: :dizzy: Setting up API endpoints as Netlify Functions in pages/api
11:34:39 AM: :dizzy: Setting up pages with getInitialProps as Netlify Functions in pages/api
11:34:39 AM: :dizzy: Setting up pages with getServerSideProps as Netlify Functions in pages/api
11:34:39 AM: :fire: Copying pre-rendered pages with getStaticProps and JSON data to Users/ivan/dev/nextweather/out_publish
11:34:39 AM: :dizzy: Setting up pages with getStaticProps and fallback: true as Netlify Functions in pages/api
11:34:39 AM: :dizzy: Setting up pages with getStaticProps and revalidation interval as Netlify Functions in pages/api
11:34:39 AM: :fire: Copying pre-rendered pages without props to Users/ivan/dev/nextweather/out_publish
11:34:39 AM: :twisted_rightwards_arrows: Setting up redirects
11:34:39 AM: :twisted_rightwards_arrows: Setting up headers
11:34:39 AM: :white_check_mark: Success! All done!
11:34:39 AM: ​
11:34:39 AM: (@netlify/plugin-nextjs onBuild completed in 757ms)
11:34:39 AM: ​
11:34:39 AM: ────────────────────────────────────────────────────────────────
11:34:39 AM: 4. Functions bundling
11:34:39 AM: ────────────────────────────────────────────────────────────────
11:34:39 AM: ​
11:34:39 AM: Packaging Functions from pages/api directory:
11:34:39 AM: - csv.ts
11:34:39 AM: - next_image.js
11:34:39 AM: - observations.js
11:34:39 AM: - tsv.js
11:34:39 AM: - next_api_csv/next_api_csv.js
11:34:39 AM: - next_api_observations/next_api_observations.js
11:34:39 AM: - next_api_tsv/next_api_tsv.js
11:34:39 AM: - next_api_util_convert/next_api_util_convert.js
11:34:39 AM: ​
11:34:39 AM: > node_modules/got/dist/source/core/utils/get-buffer.js:7:8: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 7 β”‚ for await (const chunk of stream) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/got/dist/source/create.js:157:26: error: Transforming async generator functions to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 157 β”‚ const paginateEach = (async function* (url, options) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/got/dist/source/create.js:213:12: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 213 β”‚ for await (const item of paginateEach(url, options)) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > pages/api/csv.ts:3:36: error: Could not resolve β€œ./util/convert”
11:34:39 AM: 3 β”‚ import { metersPerSecondToMph} from β€˜./util/convert’;
11:34:39 AM: β•΅ ~~~~~~~~~~~~~~~~
11:34:39 AM: > node_modules/got/dist/source/core/utils/get-buffer.js:7:8: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 7 β”‚ for await (const chunk of stream) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/got/dist/source/create.js:157:26: error: Transforming async generator functions to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 157 β”‚ const paginateEach = (async function* (url, options) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/got/dist/source/create.js:213:12: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 213 β”‚ for await (const item of paginateEach(url, options)) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/got/dist/source/create.js:157:26: error: Transforming async generator functions to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 157 β”‚ const paginateEach = (async function* (url, options) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/got/dist/source/create.js:213:12: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 213 β”‚ for await (const item of paginateEach(url, options)) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/keyv/src/index.js:18:14: warning: This call to β€œrequire” will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
11:34:39 AM: 18 β”‚ return new (require(adapters[adapter]))(opts);
11:34:39 AM: β•΅ ~~~~~~~
11:34:39 AM: > node_modules/got/dist/source/core/utils/get-buffer.js:7:8: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 7 β”‚ for await (const chunk of stream) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > node_modules/keyv/src/index.js:18:14: warning: This call to β€œrequire” will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
11:34:39 AM: 18 β”‚ return new (require(adapters[adapter]))(opts);
11:34:39 AM: β•΅ ~~~~~~~
11:34:39 AM: > node_modules/keyv/src/index.js:18:14: warning: This call to β€œrequire” will not be bundled because the argument is not a string literal (surround with a try/catch to silence this warning)
11:34:39 AM: 18 β”‚ return new (require(adapters[adapter]))(opts);
11:34:39 AM: β•΅ ~~~~~~~
11:34:39 AM: > pages/api/next_api_csv/nextPage/index.js:12072:8: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 12072 β”‚ for await (const chunk of stream) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > pages/api/next_api_csv/nextPage/index.js:12588:26: error: Transforming async generator functions to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 12588 β”‚ const paginateEach = (async function* (url, options) {
11:34:39 AM: β•΅ ~~~~~
11:34:39 AM: > pages/api/next_api_csv/nextPage/index.js:12644:12: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:39 AM: 12644 β”‚ for await (const item of paginateEach(url, options)) {
11:34:39 AM: β•΅ ~~~~~
11:34:42 AM: ​
11:34:42 AM: ────────────────────────────────────────────────────────────────
11:34:42 AM: Dependencies installation error
11:34:42 AM: ────────────────────────────────────────────────────────────────
11:34:42 AM: ​
11:34:42 AM: Error message
11:34:42 AM: A Netlify Function failed to require one of its dependencies.
11:34:42 AM: Please make sure it is present in the site’s top-level β€œpackage.json”.​
11:34:42 AM: Build failed with 4 errors:
11:34:42 AM: node_modules/got/dist/source/core/utils/get-buffer.js:7:8: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:42 AM: node_modules/got/dist/source/create.js:157:26: error: Transforming async generator functions to the configured target environment (β€œes2017”) is not supported yet
11:34:42 AM: node_modules/got/dist/source/create.js:213:12: error: Transforming for-await loops to the configured target environment (β€œes2017”) is not supported yet
11:34:42 AM: pages/api/csv.ts:3:36: error: Could not resolve β€œ./util/convert”
11:34:42 AM: ​
11:34:42 AM: Resolved config
11:34:42 AM: build:
11:34:42 AM: command: npm run build
11:34:42 AM: commandOrigin: config
11:34:42 AM: publish: /opt/build/repo/Users/ivan/dev/nextweather/out_publish
11:34:42 AM: functions:
11:34:42 AM: β€˜*’:
11:34:42 AM: node_bundler: esbuild
11:34:42 AM: functionsDirectory: /opt/build/repo/pages/api
11:34:42 AM: plugins:
11:34:42 AM: - inputs: {}
11:34:42 AM: origin: config
11:34:42 AM: package: β€˜@netlify/plugin-nextjs’
11:34:43 AM: Caching artifacts
11:34:43 AM: Started saving node modules
11:34:43 AM: Finished saving node modules
11:34:43 AM: Started saving build plugins
11:34:43 AM: Finished saving build plugins
11:34:43 AM: Started saving pip cache
11:34:43 AM: Finished saving pip cache
11:34:43 AM: Started saving emacs cask dependencies
11:34:43 AM: Finished saving emacs cask dependencies
11:34:43 AM: Started saving maven dependencies
11:34:43 AM: Finished saving maven dependencies
11:34:43 AM: Started saving boot dependencies
11:34:43 AM: Finished saving boot dependencies
11:34:43 AM: Started saving rust rustup cache
11:34:43 AM: Finished saving rust rustup cache
11:34:43 AM: Started saving go dependencies
11:34:43 AM: Finished saving go dependencies
11:34:43 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:34:43 AM: Failing build: Failed to build site
11:34:43 AM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2
11:34:43 AM: Finished processing build request in 1m44.842282737s

Hey there, @ivanoats

Sorry for the slow response. I see that this thread has been quiet since you first shared your question. Are you still encountering this issue? If so, what additional steps have you taken to debug since you first posted this? Have you seen our Next.js documentation?

Let us know! :slight_smile:

No worries.

  1. I did get a great response from tech support
  2. I have been camping and just in town to get gas so haven’t tried it yet. I will let you know next week :sunglasses:
1 Like

Sounds good, @ivanoats ! I will leave this thread open. Have a great time camping!

Ok, I did get the build to work, or succeed, but there is nothing getting output and all pages are 404-ing. It works fine on V… what am I doing wrong here?

Glad you got the build working!

We have a few threads related to this issue, but two that I recommend starting with are this Support Guide and this page not found while using Nextjs. I recommend starting with the Support Guide first!

Once you follow those steps, let us know if it is working!

yes, I had followed all those before posting.

The only thing that ended up working was removing all deploy settings. Then the Netlify UI asked to install the NextJS plugin, and then re-adding npm run build finally fixed things.

2 Likes