Hi,
I am a newbie to this forum but have been using and hosting with Netlify for 5 years. I have a handlebars site and use the Netlify CMS for most admin maintenance.
I am having a problem that I cannot find a solution for in several days of searching. The Netlify CMS interface is pretty limiting in what you can do so I have created a new page using mostly my own HTML and CSS to make it look a certain way.
I am trying to add a navigation bar to the page that links to other parts of the page. Simple enough in HTML but the builds keep failing with a cryptic message of: TypeError: Cannot read property ‘indexOf’ of undefined.
Through trial and error I have found that this is thrown when I try to add an anchor link id to a place on the page.
I recently found a couple of posts referencing something similar on Netlify and seems to allude to a problem with how Netlify checks links.
So, is using this type of anchor link not supported on Netlify or is there some trick to how to do it? I can’t find any other documentation on it.
Thanks for any help.
That’s not a particularly cryptic message.
It’s saying the precise error, which is that it’s encountered some code that is variable.indexOf
and while the code expected the variable
to probably be a String
or Array
(which have the .indexOf
method), the variable
is instead undefined
… and undefined
does not have that method.
The real key to the error is, “where it is” , what file is it in? , what’s the line number? , what’s the code at that location doing?
Is it occurring in your code or Netlify CMS code?
1 Like
Thanks for the reply.
I should have provided a little more detail but it’s not much. Those are valid questions and that is the part that is cryptic to me. I believe it is happening in the CMS code. There are no references to any of my code.
The build log says this:
12:45:42 PM: events.js:174
12:45:42 PM: throw er; // Unhandled ‘error’ event
12:45:42 PM: ^
12:45:42 PM: TypeError: Cannot read property ‘indexOf’ of undefined
12:45:42 PM: at Object. (/opt/build/repo/gulpfile.babel.js/tasks/build-content.js:391:33)
As soon as I remove the anchor tag and id, it builds normally. So it must be that. I just can’t find any documentation that explains what to do about it.
@ecgordon That particular error is being thrown from build-content.js
in /gulpfile.babel.js/tasks/
on line 391
.
However where an error is reported, may not be the ultimate source of an error.
For example I also see reference to line 174
of events.js
, but there’s very little context as you’ve heavily truncated the log.
Can you supply the full build log?
Here is the complete log:
12:45:24 PM: Netlify Build
12:45:24 PM: ────────────────────────────────────────────────────────────────
12:45:24 PM:
12:45:24 PM: ❯ Version
12:45:24 PM: @netlify /build 29.11.6
12:45:24 PM:
12:45:24 PM: ❯ Flags
12:45:24 PM: apiHost: api.netlify.com
12:45:24 PM: baseRelDir: false
12:45:24 PM: branch: production
12:45:24 PM: buildId: 647393144ff1dc0009cfdfc6
12:45:24 PM: buildbotServerSocket: /tmp/netlify-buildbot-socket
12:45:24 PM: cacheDir: /opt/build/cache
12:45:24 PM: cachedConfigPath: /tmp/netlify_config.json
12:45:24 PM: context: production
12:45:24 PM: cwd: /opt/build/repo
12:45:24 PM: deployId: 647393144ff1dc0009cfdfc8
12:45:24 PM: edgeFunctionsDistDir: /tmp/edge-647393144ff1dc0009cfdfc8
12:45:24 PM: featureFlags:
12:45:24 PM: - edge_functions_cache_cli
12:45:24 PM: - edge_functions_system_logger
12:45:24 PM: framework: metalsmith
12:45:24 PM: functionsDistDir: /tmp/zisi-647393144ff1dc0009cfdfc8
12:45:24 PM: mode: buildbot
12:45:24 PM: nodePath: /opt/buildhome/.nvm/versions/node/v10.17.0/bin/node
12:45:24 PM: repositoryRoot: /opt/build/repo
12:45:24 PM: saveConfig: true
12:45:24 PM: sendStatus: true
12:45:24 PM: siteId: 4aa709be-ef84-4788-8a7c-10bbc5d592a3
12:45:24 PM: statsd:
12:45:24 PM: host: 10.65.4.180
12:45:24 PM: port: 8125
12:45:24 PM: systemLogFile: 3
12:45:24 PM: testOpts:
12:45:24 PM: silentLingeringProcesses: ‘’
12:45:24 PM:
12:45:24 PM: ❯ Current directory
12:45:24 PM: /opt/build/repo
12:45:24 PM:
12:45:24 PM: ❯ Config file
12:45:24 PM: No config file was defined: using default values.
12:45:24 PM:
12:45:24 PM: ❯ Resolved config
12:45:24 PM: build:
12:45:24 PM: command: CI=false gulp compile
12:45:24 PM: commandOrigin: ui
12:45:24 PM: environment:
12:45:24 PM: - NETLIFY_BUILD_DEBUG
12:45:24 PM: - NETLIFY_LFS_ORIGIN_URL
12:45:24 PM: - NODE_VERSION
12:45:24 PM: - YARN_VERSION
12:45:24 PM: publish: /opt/build/repo/dist
12:45:24 PM: publishOrigin: ui
12:45:24 PM:
12:45:24 PM: ❯ Context
12:45:24 PM: production
12:45:24 PM:
12:45:24 PM: Build command from Netlify app
12:45:24 PM: ────────────────────────────────────────────────────────────────
12:45:24 PM:
12:45:24 PM: $ CI=false gulp compile
12:45:24 PM: [17:45:24] Failed to load external module @babel /register
12:45:24 PM: [17:45:24] Requiring external module babel-register
12:45:25 PM: [17:45:25] Using gulpfile /opt/build/repo/gulpfile.babel.js
12:45:25 PM: [17:45:25] Starting ‘clean’…
12:45:25 PM: [17:45:25] Finished ‘clean’ after 1.18 ms
12:45:25 PM: [17:45:25] Starting ‘set-env:production’…
12:45:25 PM: [17:45:25] Finished ‘set-env:production’ after 24 μs
12:45:25 PM: [17:45:25] Starting ‘build-misc’…
12:45:25 PM: [17:45:25] Starting ‘build-meta’…
12:45:25 PM: [17:45:25] Starting ‘build-modernizr’…
12:45:25 PM: [17:45:25] Starting ‘build-media’…
12:45:25 PM: [17:45:25] Starting ‘build-svgs’…
12:45:25 PM: [17:45:25] Starting ‘build-scripts’…
12:45:25 PM: node-resolve: setting options.jsnext is deprecated, please override options.mainFields instead
12:45:25 PM: node-resolve: setting options.main is deprecated, please override options.mainFields instead
12:45:25 PM: [17:45:25] Starting ‘update-algolia’…
12:45:26 PM: [17:45:26] Finished ‘update-algolia’ after 819 ms
12:45:31 PM: preferring built-in module ‘events’ over local alternative at ‘/opt/build/repo/node_modules/events/events.js’, pass ‘preferBuiltins: false’ to disable this behavior or ‘preferBuiltins: true’ to disable this warning
12:45:31 PM: preferring built-in module ‘events’ over local alternative at ‘/opt/build/repo/node_modules/events/events.js’, pass ‘preferBuiltins: false’ to disable this behavior or ‘preferBuiltins: true’ to disable this warning
12:45:31 PM: preferring built-in module ‘events’ over local alternative at ‘/opt/build/repo/node_modules/events/events.js’, pass ‘preferBuiltins: false’ to disable this behavior or ‘preferBuiltins: true’ to disable this warning
12:45:31 PM: preferring built-in module ‘events’ over local alternative at ‘/opt/build/repo/node_modules/events/events.js’, pass ‘preferBuiltins: false’ to disable this behavior or ‘preferBuiltins: true’ to disable this warning
12:45:31 PM: preferring built-in module ‘events’ over local alternative at ‘/opt/build/repo/node_modules/events/events.js’, pass ‘preferBuiltins: false’ to disable this behavior or ‘preferBuiltins: true’ to disable this warning
12:45:31 PM: [17:45:31] Finished ‘build-meta’ after 6.1 s
12:45:31 PM: Looking for Modernizr references
12:45:31 PM: >> Ready to build using these settings:
12:45:31 PM: >> setClasses, addTest, html5printshiv, testProp
12:45:31 PM: Building your customized Modernizr…OK
12:45:32 PM: [17:45:32] Finished ‘build-modernizr’ after 6.79 s
12:45:32 PM: Circular dependency: node_modules/array-from/index.js → node_modules/array-from/index.js
12:45:32 PM: Circular dependency: node_modules/list.js/src/index.js → node_modules/list.js/src/pagination.js → node_modules/list.js/src/index.js
12:45:32 PM: Circular dependency: node_modules/list.js/src/index.js → node_modules/list.js/src/pagination.js → /opt/build/repo/node_modules/list.js/src/index.js?commonjs-proxy → node_modules/list.js/src/index.js
12:45:37 PM: [17:45:37] Finished ‘build-scripts’ after 12 s
12:45:38 PM: [17:45:38] Finished ‘build-misc’ after 13 s
12:45:38 PM: [17:45:38] Finished ‘build-svgs’ after 13 s
12:45:39 PM: [17:45:39] Finished ‘build-media’ after 13 s
12:45:39 PM: [17:45:39] Starting ‘build-partials’…
12:45:39 PM: [17:45:39] Finished ‘build-partials’ after 231 ms
12:45:39 PM: [17:45:39] Starting ‘build-content’…
12:45:42 PM: events.js:174
12:45:42 PM: throw er; // Unhandled ‘error’ event
12:45:42 PM: ^
12:45:42 PM: TypeError: Cannot read property ‘indexOf’ of undefined
12:45:42 PM: at Object. (/opt/build/repo/gulpfile.babel.js/tasks/build-content.js:391:33)
12:45:42 PM: at initialize.exports.each (/opt/build/repo/node_modules/metalsmith-batch-dom/node_modules/cheerio/lib/api/traversing.js:293:24)
12:45:42 PM: at /opt/build/repo/gulpfile.babel.js/tasks/build-content.js:387:26
12:45:42 PM: at /opt/build/repo/node_modules/metalsmith-batch-dom/index.js:36:11
12:45:42 PM: at Array.forEach ()
12:45:42 PM: at /opt/build/repo/node_modules/metalsmith-batch-dom/index.js:30:26
12:45:42 PM: at Array.forEach ()
12:45:42 PM: at Ware. (/opt/build/repo/node_modules/metalsmith-batch-dom/index.js:29:18)
12:45:42 PM: at Ware. (/opt/build/repo/node_modules/wrap-fn/index.js:45:19)
12:45:42 PM: at next (/opt/build/repo/node_modules/ware/lib/index.js:85:20)
12:45:42 PM: Emitted ‘error’ event at:
12:45:42 PM: at Stream.onerror (/opt/build/repo/node_modules/readable-stream/lib/_stream_readable.js:640:52)
12:45:42 PM: at Stream.emit (events.js:198:13)
12:45:42 PM: at /opt/build/repo/node_modules/highland/lib/index.js:779:18
12:45:42 PM: at Stream.s._send (/opt/build/repo/node_modules/highland/lib/index.js:1018:9)
12:45:42 PM: at Stream.write (/opt/build/repo/node_modules/highland/lib/index.js:1087:18)
12:45:42 PM: at Stream._send (/opt/build/repo/node_modules/highland/lib/index.js:565:19)
12:45:42 PM: at /opt/build/repo/node_modules/highland/lib/index.js:2014:25
12:45:42 PM: at /opt/build/repo/node_modules/highland/lib/index.js:1051:9
12:45:42 PM: at Stream.s._send (/opt/build/repo/node_modules/highland/lib/index.js:1018:9)
12:45:42 PM: at Stream.write (/opt/build/repo/node_modules/highland/lib/index.js:1087:18)
12:45:42 PM:
12:45:42 PM: “build.command” failed
12:45:42 PM: ────────────────────────────────────────────────────────────────
12:45:42 PM:
12:45:42 PM: Error message
12:45:42 PM: Command failed with exit code 1: CI=false gulp compile (Search results for '"non-zero exit code: 1"' - Netlify Support Forums )
12:45:42 PM:
12:45:42 PM: Error location
12:45:42 PM: In Build command from Netlify app:
12:45:42 PM: CI=false gulp compile
12:45:42 PM:
12:45:42 PM: Resolved config
12:45:42 PM: build:
12:45:42 PM: command: CI=false gulp compile
12:45:42 PM: commandOrigin: ui
12:45:42 PM: environment:
12:45:42 PM: - NETLIFY_BUILD_DEBUG
12:45:42 PM: - NETLIFY_LFS_ORIGIN_URL
12:45:42 PM: - NODE_VERSION
12:45:42 PM: - YARN_VERSION
12:45:42 PM: publish: /opt/build/repo/dist
12:45:42 PM: publishOrigin: ui
12:45:44 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums )
12:45:44 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:45:44 PM: Failing build: Failed to build site
12:45:44 PM: Finished processing build request in 45.947s
@ecgordon You should check your events.js
file, line 174
, to see how it could be related to your issue.
@nathanmartin Yes, that’s where I have been digging. GULP was pointing out where I was trying to use the anchor id. I had it inside a paragraph tag. Oops. A careless mistake done in a hurry but I could not see it. I moved the tag to the outside div and it is working correctly now.
Thank you for your assistance.
SamO
May 30, 2023, 6:27pm
8
glad you found your solution @ecgordon