question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'some' of undefined

See original GitHub issue

🐞 Bug report

What modules are related to this issue?

  • express-engine

Is this a regression?

It worked with version 8

Description

ng add @nguniversal/express-engine@9.1.1 --client-project={{project_id}} Installing packages for tooling via npm. Installed packages for tooling via npm. Cannot read property ‘some’ of undefined

🌍 Your Environment



$ ng version
Angular CLI: 9.1.9
Node: 12.18.0
OS: linux x64

Angular: 9.1.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.9
@angular-devkit/build-angular     0.901.9
@angular-devkit/build-optimizer   0.901.9
@angular-devkit/build-webpack     0.901.9
@angular-devkit/core              9.1.9
@angular-devkit/schematics        9.1.9
@angular/cdk                      9.1.3
@angular/cli                      9.1.9
@angular/fire                     5.4.2
@angular/material                 9.1.3
@ngtools/webpack                  9.1.9
@nguniversal/common               9.1.1
@nguniversal/express-engine       9.1.1
@schematics/angular               9.1.9
@schematics/update                0.901.9
rxjs                              6.5.5
typescript                        3.9.5
webpack                           4.43.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

28reactions
Idekicommented, Jul 18, 2020

I got that error too. After doing some modifications of your code here is what I found out (in my case):

The error comes from /universal/modules/common/schematics/utils/utils.ts Specifically in the addInitialNavigation function.

It seems that you are looking for properties of the existingOptions.

existingOptions.properties.some

This is the some that breaks.

Just before the exception happens, I printed the existingOptions.escapedText which showed (in my case):

routerOptions

After doing a lookup in my project, I found only 1 place with this. In my app-routing.module.ts

Here is it:

import { Routes, RouterModule, ExtraOptions } from '@angular/router';
const routes: Routes = [
  {
    path: '',
    pathMatch: 'full',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
  },
  {
    path: 'home',
    loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
  },
  {
    path: 'download',
    loadChildren: () => import('./download/download.module').then(m => m.DownloadModule)
  },
  // otherwise redirect to home
  {
    path: '**',
    redirectTo: ''
  }
];
const routerOptions: ExtraOptions = {
  scrollPositionRestoration: 'enabled',
  anchorScrolling: 'enabled'
};
@NgModule({
  imports: [
    RouterModule.forRoot(routes, routerOptions)
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

It looks like your are not handling the ExtraOptions properly, or it might be the way I declared it.

If I roll back everything, remove my routerOptions (no options at all), then the whole process completes without any problem.

I hope this helps you fix the issue properly.


As for a quick’n’dirty fix:

  1. Open node_modules@nguniversal\common\schematics\utils\utils.js
  2. in function addInitialNavigation(node) replace: if (existingOptions && existingOptions.properties.some( with if (existingOptions && existingOptions.properties && existingOptions.properties.some(
  3. replace: const routerOptions = existingOptions ? ts.updateObjectLiteral( with const routerOptions = existingOptions && existingOptions.properties ? ts.updateObjectLiteral(
  4. run ng add @nguniversal/express-engine

After that the migration completed

Skipping installation: Package already installed  
CREATE server.ts (2017 bytes)
UPDATE package.json (3621 bytes)
UPDATE angular.json (5887 bytes)
UPDATE src/app/app-routing.module.ts (2657 bytes)
√ Packages installed successfully.

Note: my app-routing.module.ts was wrong after that as my routerOptions were not used anymore. And instead it declared an initialNavigation setting. Most probably it is caused by the way I fixed the problem, So I just rolled back the changes for app-routing.module.ts, and integrated the initialNavigation: ‘enabled’

const routerOptions: ExtraOptions = {
  scrollPositionRestoration: 'enabled',
  anchorScrolling: 'enabled',
  initialNavigation: 'enabled'
};

@NgModule({
  imports: [
    RouterModule.forRoot(routes, routerOptions)
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }
0reactions
angular-automatic-lock-bot[bot]commented, Oct 16, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined. Undefined means that a variable has been declared but has not been assigned a value....
Read more >
TypeError: Cannot read property 'some' of undefined
javascript - I keep getting this error "TypeError: Cannot read property 'some' of undefined" - Stack Overflow. Stack Overflow for Teams – Start ......
Read more >
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
[2.6.0] TypeError: Cannot read property 'some' of undefined ...
Description Just tried to update apollo-server-express from 2.5.1 → 2.6.0 but it's failing with the following: TypeError: Cannot read ...
Read more >
Uncaught TypeError: Cannot read property 'some' of undefined
Uncaught TypeError : Cannot read property of undefined error is probably easiest to understand from the perspective of undefined, since undefined ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found