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.

Getting Error while angular universal server running

See original GitHub issue

Bug Report

What is the expected behavior?

should be renders serverside properly.

What is the current behavior?

when i navigate to port 4000,it returns like this.

Node Express server listening on http://localhost:4000 Warning: Flex Layout loaded on the server without FlexLayoutServerModule /home/ss2/app/dist/server.js:344 throw error; ^

ReferenceError: requestAnimationFrame is not defined at AnimationFrameAction.requestAsyncId (/home/ss2/app/dist/server.js:30505:40) at AnimationFrameAction.AsyncAction.schedule (/home/ss2/app/dist/server.js:29678:35)

What modules are related to this issue?

- In Angular app ,have used Material,no furher animation Modules.
- [ ] express-engine


Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

4reactions
michelepatrassicommented, Sep 12, 2019

@sreeragnair @munkhbayar17 requestAnimationFrame is defined in the browser, not in node where your server side application runs. Add the following code in your server.ts to define it plus cancelAnimationFrame:

global['requestAnimationFrame'] = function(callback, element) {
  let lastTime = 0;
  const currTime = new Date().getTime();
  const timeToCall = Math.max(0, 16 - (currTime - lastTime));
  const id = setTimeout(function() { callback(currTime + timeToCall); },
    timeToCall);
  lastTime = currTime + timeToCall;
  return id;
};

global['cancelAnimationFrame'] = function(id) {
  clearTimeout(id);
};

I hope this will help!

1reaction
raju-kommidicommented, Nov 29, 2019

@sreeragnair @munkhbayar17 requestAnimationFrame is defined in the browser, not in node where your server side application runs. Add the following code in your server.ts to define it plus cancelAnimationFrame:

global['requestAnimationFrame'] = function(callback, element) {
  let lastTime = 0;
  const currTime = new Date().getTime();
  const timeToCall = Math.max(0, 16 - (currTime - lastTime));
  const id = setTimeout(function() { callback(currTime + timeToCall); },
    timeToCall);
  lastTime = currTime + timeToCall;
  return id;
};

global['cancelAnimationFrame'] = function(id) {
  clearTimeout(id);
};

I hope this will help!

Thanks, It works for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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