Forge Currency Exchange example - Error: Cannot read properties of undefined (reading 'length')

Hi,

I’m trying to follow this example Forge app and I can’t seem to deploy the app to my cloud instance.

I’ve registered the app, run ‘npm install’ as per the instructions but when I try to run ‘forge deploy’ I run into the following error:

Error: Cannot read properties of undefined (reading 'length')

TypeError: Cannot read properties of undefined (reading 'length')
    at Function.glob.hasMagic (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\glob\glob.js:107:30)
    at FileSystemReader.hasGlobSpecialChars (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\@forge\cli-shared\out\file-system\file-system-reader.js:59:23)
    at C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\@forge\cli-shared\out\shared\read-app-config-files.js:13:30
    at Array.map (<anonymous>)
    at Object.exports.listGitIgnoreFiles (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\@forge\cli-shared\out\shared\read-app-config-files.js:12:82)
    at LintService.run (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\out\service\lint-service.js:13:49)
    at DeployController.verifyPreDeployment (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\controller\deploy-controller.js:72:56)
    at DeployController.run (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\controller\deploy-controller.js:97:24)
    at C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\register-deployment-commands.js:14:50
    at Command.actionProcessor (C:\Users\Admin\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\command.js:76:38)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Any assistance would be appreciated

Hi @BradQ ,

This looks interesting. I tried cloning a fresh copy of the repo and followed the steps and was able to deploy without errors.

To cover all the bases, I used the following versions when I tried it out.

iragudo forge-currency-exchange-orig % forge --version
4.0.0
iragudo forge-currency-exchange-orig % node --version
v16.14.0

What versions are you running on?

Cheers,
Ian

Hi @iragudo, thanks for the reply. I’m running 4.1.0 and 16.14.0 respectively

Hi @BradQ , I’m currently stumped with this one. Since your logs indicate that you are using a Windows machine, I spawned a Windows instance, used the same version of node and forge, ran Docker, cloned the project, and after doing all of these, I was able to successfully deploy a freshly cloned project.

Are there any other steps I’m missing?

Nope, that should be everything. This is on a fairly fresh machine too (about 2 weeks old) so there shouldn’t be much that is interfering with the setup.

For reference I’m able to create a fresh project and run forge install, deploy and tunnel on it with no issue, so I’m also kinda stumped.

So far, I don’t think there’s a problem with the sample app and this seems to be an isolated case. That said, since you can create a fresh project, you can then use the sample app as reference - copy the customFieldType module from manifest and implement (or copy) the functions that you need.

As I cannot replicate the issue, it is a bit of a challenge to diagnose a fix. My apologies.

Cheers,
Ian

Hi @iragudo. Has, by any chance, been any update on this?

I just moved to a new laptop (both new and old on Windows 11) and after setting up Forge CLI 4.4.1 and registering my custom app, I get the exact same error. Node version 16.15.1

$ forge deploy --verbose
Deploying your app to the development environment.
Press Ctrl+C to cancel.

Running forge lint...

Error: Cannot read properties of undefined (reading 'length')

TypeError: Cannot read properties of undefined (reading 'length')
    at Function.glob.hasMagic (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\glob\glob.js:107:30)
    at FileSystemReader.hasGlobSpecialChars (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\@forge\cli-shared\out\file-system\file-system-reader.js:59:23)
    at C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\@forge\cli-shared\out\shared\read-app-config-files.js:13:30
    at Array.map (<anonymous>)
    at Object.exports.listGitIgnoreFiles (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\@forge\cli-shared\out\shared\read-app-config-files.js:12:82)
    at LintService.run (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\out\service\lint-service.js:13:49)
    at DeployController.verifyPreDeployment (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\controller\deploy-controller.js:72:56)
    at DeployController.run (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\controller\deploy-controller.js:97:24)
    at C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\register-deployment-commands.js:14:50
    at Command.actionProcessor (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\out\command-line\command.js:76:38)

While this is a completely custom Forge App, my collegues have been able to deploy/install via their existing CLI installation when working on fresh copies of the codebase as normal.
In the meanwhile, me installing the same version of the CLI as per official instructions ended up in the above behaviour, even after I was able to login with my new auth token.

EDIT: I believe I’ve found the root cause of this problem. Basically, all lines in the .gitignore are being passed down to the Glob library by @forge/lint
Function.glob.hasMagic (C:\Users\John\AppData\Roaming\npm\node_modules\@forge\cli\node_modules\glob\glob.js:96:11)
which throws this error.

This is because many Git-on-windows configurations check out files with Win-style line endings (CRLF), which doesn’t play well with the Glob library and was probably the cause of other issues like this.

To fix one can simply do

git config --global core.autocrlf input

Before cloning a repo, to ensure line-endings are checked-out as-is, which usually means Unix-style (LF) line endings, that work fine with the Linter+Glob.

1 Like