.toml file error during dynamic route creation on nuxt js

Hello friends;

I need to create dynamic route for my Static Nuxt js project. I followed the directions. nuxt.config.js and toml file are below but I am getting error. Can you help me? If I remove the generate field, everything works normally.

 generate: {
    routes(callback) {
      axios
        .get('https://xxxxxxx/url-list')
        .then((res) => {
          const routes = res.data.map((prod) => {
            return '/products/' + prod.link;
          });
          callback(null, routes);
        })
        .catch(callback);
    }
  },
## This is the configuration file for Netlify
## https://docs.netlify.com/configure-builds/file-based-configuration/

[build]
  command = "npm run generate" # how to build your project
  functions = "netlify/functions" # where Netlify Functions live
  publish = "dist" # where the built project lives

## Learn more about redirects here
## https://docs.netlify.com/routing/redirects/#syntax-for-the-netlify-configuration-file
## https://docs.netlify.com/routing/redirects/redirect-options/

[[redirects]]
  from = "/api/*" # simplify all calls to serverless functions
  to = "/.netlify/functions/:splat" # all function calls will go to this path
  status = 200 # ok code
  force = true # ensure to always redirect

[functions]
  node_bundler = "esbuild"

[build.environment]
  NETLIFY_USE_YARN = "true"

Hey there, @mahiraltinkaya :wave:

Can you please share your full deploy log (rather than the screenshot above) as well as the URL to your deployed site? This will help us investigate further.

Thanks!

1 Like

Hey Hillary;
I’m glad to you see. I solved this problem with an environment that is shared below. However, I am open to a more efficient solution suggestion.

[build.environment]
  NODE_OPTIONS = "--max_old_space_size=4096"
9:20:51 AM: Waiting for other deploys from your team to complete. Check the queue: https://app.netlify.com/teams/atilerturk/builds
9:22:56 AM: Build ready to start
9:22:56 AM: ---------------------------------------------------------------------WARNING: Starter plan site builds from private, organization-owned GitHub repositories will fail after September 30, 2022.This build was triggered from a private, organization-owned GitHub repository, which is now a feature of the Pro plan.To avoid service disruption, please upgrade your plan or change your repository settings by September 30, 2022.If you upgrade to Pro, you can get the first month free:https://app.netlify.com/teams/atilerturk/billing/pricing?plan=trialFor more details, including how to continue building your site on the Starter plan, visit our FAQ page:https://www.netlify.com/pricing/private-org-repo-faq---------------------------------------------------------------------
9:22:59 AM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
9:22:59 AM: build-image tag: v4.10.1
9:22:59 AM: buildbot version: 1c362ef848ac5e35535bdb572ebca893db28c8a0
9:22:59 AM: Fetching cached dependencies
9:22:59 AM: Starting to download cache of 208.3MB
9:23:01 AM: Finished downloading cache in 1.969207427s
9:23:01 AM: Starting to extract cache
9:23:03 AM: Finished extracting cache in 2.180724355s
9:23:03 AM: Finished fetching cache in 4.245929634s
9:23:03 AM: Starting to prepare the repo for build
9:23:04 AM: Preparing Git Reference refs/heads/develop
9:23:05 AM: Parsing package.json dependencies
9:23:05 AM: Starting build script
9:23:05 AM: Installing dependencies
9:23:05 AM: Python version set to 2.7
9:23:06 AM: Started restoring cached node version
9:23:06 AM: Finished restoring cached node version
9:23:07 AM: v16.17.0 is already installed.
9:23:07 AM: Now using node v16.17.0 (npm v8.15.0)
9:23:07 AM: Started restoring cached build plugins
9:23:07 AM: Finished restoring cached build plugins
9:23:07 AM: Attempting ruby version 2.7.2, read from environment
9:23:08 AM: Using ruby version 2.7.2
9:23:08 AM: Using PHP version 8.0
9:23:08 AM: Started restoring cached yarn cache
9:23:10 AM: Finished restoring cached yarn cache
9:23:10 AM: No yarn workspaces detected
9:23:10 AM: Started restoring cached node modules
9:23:10 AM: Finished restoring cached node modules
9:23:10 AM: Installing NPM modules using Yarn version 1.22.10
9:23:10 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
9:23:10 AM: npm WARN config location in the cache, and they are managed by
9:23:10 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
9:23:11 AM: yarn install v1.22.10
9:23:11 AM: [1/4] Resolving packages...
9:23:11 AM: success Already up-to-date.
9:23:11 AM: Done in 0.50s.
9:23:11 AM: NPM modules installed using Yarn
9:23:11 AM: Started restoring cached go cache
9:23:11 AM: Finished restoring cached go cache
9:23:11 AM: Installing Go version 1.16.5 (requested 1.16.5)
9:23:15 AM: unset GOOS;
9:23:15 AM: unset GOARCH;
9:23:15 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.16.5.linux.amd64';
9:23:15 AM: export PATH="/opt/buildhome/.gimme/versions/go1.16.5.linux.amd64/bin:${PATH}";
9:23:15 AM: go version >&2;
9:23:15 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.16.5.linux.amd64.env"
9:23:15 AM: go version go1.16.5 linux/amd64
9:23:15 AM: Installing missing commands
9:23:15 AM: Verify run directory
9:23:16 AM: ​
9:23:16 AM: ────────────────────────────────────────────────────────────────
9:23:16 AM:   Netlify Build                                                 
9:23:16 AM: ────────────────────────────────────────────────────────────────
9:23:16 AM: ​
9:23:16 AM: ❯ Version
9:23:16 AM:   @netlify/build 27.18.4
9:23:16 AM: ​
9:23:16 AM: ❯ Flags
9:23:16 AM:   baseRelDir: true
9:23:16 AM:   buildId: 632bfec3db7935000988f05f
9:23:16 AM:   deployId: 632bfec3db7935000988f061
9:23:16 AM: ​
9:23:16 AM: ❯ Current directory
9:23:16 AM:   /opt/build/repo
9:23:16 AM: ​
9:23:16 AM: ❯ Config file
9:23:16 AM:   /opt/build/repo/netlify.toml
9:23:16 AM: ​
9:23:16 AM: ❯ Context
9:23:16 AM:   production
9:23:16 AM: ​
9:23:16 AM: ────────────────────────────────────────────────────────────────
9:23:16 AM:   1. build.command from netlify.toml                            
9:23:16 AM: ────────────────────────────────────────────────────────────────
9:23:16 AM: ​
9:23:16 AM: $ npm run generate
9:23:17 AM: npm WARN config tmp This setting is no longer used.  npm stores temporary files in a special
9:23:17 AM: npm WARN config location in the cache, and they are managed by
9:23:17 AM: npm WARN config     [`cacache`](http://npm.im/cacache).
9:23:17 AM: > nuxt-toolbox@1.0.0 generate
9:23:17 AM: > nuxt generate
9:25:02 AM: <--- Last few GCs --->
9:25:02 AM: [1389:0x5418900]   104270 ms: Scavenge 1977.8 (2074.7) -> 1968.1 (2074.7) MB, 6.0 / 0.0 ms  (average mu = 0.223, current mu = 0.208) allocation failure
9:25:02 AM: [1389:0x5418900]   104296 ms: Scavenge 1978.0 (2074.7) -> 1970.8 (2074.7) MB, 11.8 / 0.0 ms  (average mu = 0.223, current mu = 0.208) allocation failure
9:25:02 AM: [1389:0x5418900]   104352 ms: Scavenge 1983.6 (2074.7) -> 1971.7 (2074.7) MB, 12.3 / 0.0 ms  (average mu = 0.223, current mu = 0.208) allocation failure
9:25:02 AM: <--- JS stacktrace --->
9:25:02 AM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
9:25:02 AM:  1: 0xb02930 node::Abort() [node]
9:25:02 AM:  2: 0xa18149 node::FatalError(char const*, char const*) [node]
9:25:02 AM:  3: 0xcdd16e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
9:25:02 AM:  4: 0xcdd4e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
9:25:02 AM:  5: 0xe94b55  [node]
9:25:02 AM:  6: 0xe95636  [node]
9:25:02 AM:  7: 0xea3b5e  [node]
9:25:02 AM:  8: 0xea45a0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9:25:02 AM:  9: 0xea751e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
9:25:02 AM: 10: 0xe68a5a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
9:25:02 AM: 11: 0x11e17c6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
9:25:02 AM: 12: 0x15d5439  [node]
9:25:04 AM: Aborted (core dumped)
9:25:04 AM: ​
9:25:04 AM: ────────────────────────────────────────────────────────────────
9:25:04 AM:   "build.command" failed                                        
9:25:04 AM: ────────────────────────────────────────────────────────────────
9:25:04 AM: ​
9:25:04 AM:   Error message
9:25:04 AM:   Command failed with exit code 134: npm run generate (https://ntl.fyi/exit-code-134)
9:25:04 AM: ​
9:25:04 AM:   Error location
9:25:04 AM:   In build.command from netlify.toml:
9:25:04 AM:   npm run generate
9:25:04 AM: ​
9:25:04 AM:   Resolved config
9:25:04 AM:   build:
9:25:04 AM:     command: npm run generate
9:25:04 AM:     commandOrigin: config
9:25:04 AM:     environment:
9:25:04 AM:       - NETLIFY_USE_YARN
9:25:04 AM:     publish: /opt/build/repo/dist
9:25:04 AM:     publishOrigin: config
9:25:04 AM:   functions:
9:25:04 AM:     '*':
9:25:04 AM:       node_bundler: esbuild
9:25:04 AM:   functionsDirectory: /opt/build/repo/netlify/functions
9:25:04 AM:   redirects:
9:25:04 AM:     - force: true
9:25:04 AM:       from: /api/*      status: 200      to: /.netlify/functions/:splat  redirectsOrigin: configCaching artifacts
9:25:04 AM: Started saving node modules
9:25:04 AM: Finished saving node modules
9:25:04 AM: Started saving build plugins
9:25:04 AM: Finished saving build plugins
9:25:04 AM: Started saving yarn cache
9:25:08 AM: Finished saving yarn cache
9:25:08 AM: Started saving pip cache
9:25:08 AM: Finished saving pip cache
9:25:08 AM: Started saving emacs cask dependencies
9:25:08 AM: Finished saving emacs cask dependencies
9:25:08 AM: Started saving maven dependencies
9:25:08 AM: Finished saving maven dependencies
9:25:08 AM: Started saving boot dependencies
9:25:08 AM: Finished saving boot dependencies
9:25:08 AM: Started saving rust rustup cache
9:25:08 AM: Finished saving rust rustup cache
9:25:08 AM: Started saving go dependencies
9:25:08 AM: Finished saving go dependencies
9:25:08 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:25:08 AM: Creating deploy upload records
9:25:09 AM: Failing build: Failed to build site
9:25:09 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:25:09 AM: Finished processing build request in 2m9.600923211s

Hey there, @mahiraltinkaya :wave:

Thanks for reaching out! We think it is ok to use this solution.

In terms of root cause, we think the original issue may actually be happening because your code is leaking memory, which is using up the 512 mg of memory that node.js provides. If you want to spend time debugging this further, I would suggest investigating what is causing so much memory to be used (for example, image processing, etc.) But if you are happy with the workaround, you can proceed using it!

We have this resource that you can use to get started, which includes examples with nuxt builds :

1 Like