Resolving Common Now CLI Errors

I love the idea of being able to create custom components to use in ServiceNow’s UI Builder, but I end up feeling anxious every time I’m faced with getting a project up and running on my local machine. I find myself asking, “what problems am I going to run into this time?” I decided to start recording the errors I ran into and how I resolved them. Doing this made my life so much easier! Whenever I ran into one of those errors, I knew right where to go to find the solution and was able to quickly get back on my merry way. Hopefully sharing some of those solutions will help you as well!

Missing “Keytar” Module

The following error can occur when creating a project:

Error: Cannot find module 'keytar'

This error is thrown when you try to use the CLI with the wrong node version. The ServiceNow CLI currently works with node 12.16.1.

Steps to Resolve Error

  1. Switch to node 12.16.1
    • You may need to install node 12.16.1 first. Node 12.16.1 requires python 2.x, so make sure you have that installed as well.
    • Run nvm use 12.16.1
  2. Delete node_modules and package-lock.json (or the yarn.lock if using yarn) from the project directory
  3. Uninstall the ui-component extension
    • snc extension remove --name ui-component
  4. Reinstall the ui-component extension (this time with node 12.16.1)
    • snc extension add --name ui-component
  5. Reinstall node_modules
    • npm install

Unsupported Instance Version

The following error can occur when deploying your component to your instance:

ERROR in Instance version "Tokyo" unsupported!"

This error is thrown when coming back to a project that has not been deployed since the latest ServiceNow release.

Steps to Resolve Error

Edit both of the following files so that the array of versions includes the version of ServiceNow your instance is on. For example, let s=["rome","sandiego","tokyo"].

  • ~/.snc/.extensions/ui-component/node_modules/@servicenow/cli-glide/support/index.js
  • <path to your component directory>/node_modules/@servicenow/cli-glide/support/index.js

Note: running npm install might revert the changes you’ve made, but at least you know where to go to fix it again!

Invalid Scope Name

The following error can occur when deploying your component to your instance:

ERROR in Response code 400 (Bad Request): Scope name is invalid, please try a different scope name

This error is thrown when you try to deploy a component to an app scope that doesn’t have a sys_app record. This can happen when you installed the app via the store or the “My Company Applications” module. It can also happen when an instance was cloned over and the sys_app record lost.

Steps to Resolve Error

You can solve this problem by importing the original sys_app record into your instance.

If you don’t have an update set of the app or the original sys_app record to import, you won’t be able to deploy to that scope. If that’s the case and changing the component’s scope would be helpful, see my blog post on changing a component’s scope.

Unsupported Node Sass Version

The following error can occur when running a command via the ServiceNow CLI on a version of node that is incompatible with your version of Node Sass:

ERROR: Node Sass does not yet support your current environment

This error (and other similar variations of the error) is thrown when you try to setup or deploy an app through a CLI version or node version that you did not create the app in. For example, if you started a project on an older version of the CLI and later upgraded your CLI, you could run into this error when redeploying the project. That is because the version of Node Sass that was installed with the old CLI version is no longer compatible with the newer version of node that the CLI upgrade uses.

Steps to Resolve Error

The quickest workaround is switching to the node version that was used to create the app (i.e. nvm use 12.16.1) and running the command again. However, that is only a temporary fix. Ultimately you’ll want to upgrade your Node Sass version. You can do so by running npm rebuild node-sass. In my case, I had to install python2* before that command would work. Also, make sure you are on the correct version of node for the corresponding version of the ServiceNow CLI you are running.

*python2 is no longer supported on macOS 12.3+. To install python2, I used the link to the macOS 64-bit installer provided in the solution to this question in Stack Overflow: https://stackoverflow.com/a/71740144/10667677

Wrong App Scope

If you forgot to specify your app scope when creating a project, or if you set the project to the wrong app scope, see my blog post on changing a component’s scope!