Internal Server Error: 500 - TypeError: Cannot read properties of null (reading 'split')

Product/components used and version/fix level:

@c8y/cli

Detailed explanation of the problem:

I am trying to run through some web development tutorials (which previously worked earlier this year) for our current project, and we noticed that there are internal server errors and it appears that it has to do with the source code. ’

I have run other versions when compiling and the error still persists.

It appears to have something to do with the split function in an index.js file.

I’ve downloaded the correct version of NodeJS, we have tried to npm install --legacy-peer-deps after deleting the node_modules and the error still persisted.

I have tried to include as much information as possible to help gauge the issue, and if you need to see anything else I will do my best to provide it.

UPDATE: It doesn’t initially provide these errors or when I try to login when I start the server through the package.json file with npm run start.

Error messages / full error message screenshot / log file:

When running server:

Warning: Dependency ngx-bootstrap cannot be resolved for module federation sharing.

http://localhost:9000/apps/tutorial-application/ 10 % - building - 0/1 entries 66/71 dependencies 25/47 modules

http://localhost:9000/apps/tutorial-application/ 99 % - cache - begin idle



Entrypoint bootstrap 1.51 MiB = bootstrap.js
Chunk Group app 981 KiB = vendors-node_modules_zone_js_dist_zone_js-node_modules_angular_platform-browser_fesm2020_anim-3c6a33.js 967 KiB app.js 14.3 KiB
Chunk Group branding =
webpack 5.76.1 compiled successfully in 11804 ms

http://localhost:9000/apps/tutorial-application/ done - finished in 11 s - 876.764 ms

When opening the link to the server:

TypeError: Cannot read properties of null (reading 'split')
    at required (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\requires-port\index.js:13:23)
    at Object.common.setupOutgoing (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\common.js:101:7)
    at Array.stream (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:127:14)
    at ProxyServer.<anonymous> (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at HttpProxyMiddleware.middleware (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy-middleware\dist\http-proxy-middleware.js:22:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: Cannot read properties of null (reading 'split')
    at required (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\requires-port\index.js:13:23)
    at Object.common.setupOutgoing (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\common.js:101:7)
    at Array.stream (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:127:14)
    at ProxyServer.<anonymous> (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at HttpProxyMiddleware.middleware (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy-middleware\dist\http-proxy-middleware.js:22:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: Cannot read properties of null (reading 'split')
    at required (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\requires-port\index.js:13:23)
    at Object.common.setupOutgoing (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\common.js:101:7)
    at Array.stream (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:127:14)
    at ProxyServer.<anonymous> (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at HttpProxyMiddleware.middleware (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy-middleware\dist\http-proxy-middleware.js:22:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: Cannot read properties of null (reading 'split')
    at required (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\requires-port\index.js:13:23)
    at Object.common.setupOutgoing (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\common.js:101:7)
    at Array.stream (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:127:14)
    at ProxyServer.<anonymous> (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at HttpProxyMiddleware.middleware (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy-middleware\dist\http-proxy-middleware.js:22:32)

When entering login information:

server_error_login

And this is the server response to this:

at processTicksAndRejections (node:internal/process/task_queues:96:5)
TypeError: Cannot read properties of null (reading 'split')
    at required (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\requires-port\index.js:13:23)
    at Object.common.setupOutgoing (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\common.js:101:7)
    at Array.stream (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\passes\web-incoming.js:127:14)
    at ProxyServer.<anonymous> (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy\lib\http-proxy\index.js:81:21)
    at HttpProxyMiddleware.middleware (C:\Users\username\OneDrive - Novanta\Documents\Project test\Cumulocity\Web Dev Tutorials\tutorial-application\node_modules\http-proxy-middleware\dist\http-proxy-middleware.js:22:32)

The index.js file code:

'use strict';

/**
 * Check if we're required to add a port number.
 *
 * @see https://url.spec.whatwg.org/#default-port
 * @param {Number|String} port Port number we need to check
 * @param {String} protocol Protocol we need to check against.
 * @returns {Boolean} Is it a default port for the given protocol
 * @api private
 */
module.exports = function required(port, protocol) {
  protocol = protocol.split(':')[0];
  port = +port;

  if (!port) return false;

  switch (protocol) {
    case 'http':
    case 'ws':
    return port !== 80;

    case 'https':
    case 'wss':
    return port !== 443;

    case 'ftp':
    return port !== 21;

    case 'gopher':
    return port !== 70;

    case 'file':
    return false;
  }

  return port !== 0;
};
1 Like

Hi Antonio,

can you let us know which version of the tutorial app you have scaffolded using the @c8y/cli?

Can you also provide the start script used within your package.json file, that is executed when running npm run start? (it should be something like c8ycli server [...])

Regards,
Tristan

Here is the package.json file with version info:

{
  "name": "c8y-app-tutorial",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "c8ycli server -u <<My Server :)>>",
    "build": "c8ycli build",
    "deploy": "c8ycli deploy",
    "locale-extract": "c8ycli locale-extract",
    "postinstall": "ngcc",
    "test": "jest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@angular/animations": "12.2.14",
    "@angular/cdk": "12.2.13",
    "@angular/common": "12.2.14",
    "@angular/compiler": "12.2.14",
    "@angular/core": "12.2.14",
    "@angular/forms": "12.2.14",
    "@angular/platform-browser": "12.2.14",
    "@angular/platform-browser-dynamic": "12.2.14",
    "@angular/router": "12.2.14",
    "@angular/upgrade": "12.2.14",
    "@c8y/client": "1015.0.323",
    "@c8y/ngx-components": "1015.0.323",
    "@ngx-translate/core": "13.0.0",
    "rxjs": "~6.6.3",
    "zone.js": "~0.11.4",
    "@c8y/style": "1015.0.323"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "12.2.14",
    "@angular/compiler-cli": "12.2.14",
    "@angular/language-service": "12.2.14",
    "@angular/service-worker": "12.2.14",
    "@angular/localize": "12.2.14",
    "@types/jest": "^27.0.3",
    "jest": "^27.4.5",
    "jest-preset-angular": "^11.0.1",
    "typescript": "4.2.4",
    "@c8y/cli": "1015.0.323"
  },
  "c8y": {
    "application": {
      "name": "c8y-app-tutorial",
      "contextPath": "c8y-app-tutorial",
      "key": "c8y-app-tutorial-application-key",
      "dynamicOptionsUrl": "/apps/public/public-options/options.json"
    },
    "cli": {}
  },
  "browserslist": [
    "last 2 major versions"
  ]
}

What is your actual value for this one? It should start with http:// or https://, maybe you are missing the protocol?

2 Likes

I was using the http:// protocol for our server. The same http:// works when I deploy it as well.

Ahh yes, I see. When I was running it in the CLI, I left out http://, and that’s why package.json was working fine.

I originally was using this as the prompt:

npx c8ycli server -u my.server.cumulocity.com

When I should have been putting:

npx c8ycli server -u http://my.server.cumulocity.com

Now it is functioning correctly.

Perhaps a mention about that can be added when using the example;

npx c8ycli server -u <<C8Y-URL>>

specifically, that C8Y-URL itself should also have the protocol in it, as it may not be so obvious to a beginner learning about c8y/cli for their first time.

Thank you Tristan.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.