Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "path" argument must be of type string. Received undefined #2

Open
SDAdham opened this issue Jul 13, 2021 · 4 comments
Open

The "path" argument must be of type string. Received undefined #2

SDAdham opened this issue Jul 13, 2021 · 4 comments

Comments

@SDAdham
Copy link

SDAdham commented Jul 13, 2021

I am trying your implementation but I am getting The "path" argument must be of type string. Received undefined when I refresh localhost, not sure why. I'm still investigating...

One change on my end, I cannot use import { ɵCommonEngine as CommonEngine } from '@nguniversal/common/​engine'; because it causes Cannot find module '@nguniversal/common/​engine' or its corresponding type declarations.
This import { CommonEngine } from '@nguniversal/common/engine'; works, but not sure if that's good to go.

@sbarbat
Copy link
Contributor

sbarbat commented Jul 13, 2021

Hey @SDAdham, thats probably happening because you haven't defined the path of the routes you want to cache, you need to do it like this:

const routeCaches = [
    {path: '/', ttl: 86400},
    {path: '/explore-recipes', ttl: 86400, useQueryParams: true}
];

@SDAdham
Copy link
Author

SDAdham commented Jul 13, 2021

hi @sbarbat ,

I did the route cache as this:

const routeCaches = [
    { path: '*', ttl: 86400, useQueryParams: true },
    // { path: '/explore-recipes', ttl: 86400, useQueryParams: true },
  ];

and then:

let routeCache: RouteCache;
      try {
        routeCache = setupOptions.routeCaches?.filter(
          route =>
            route.path === req.path || new RegExp('^' + route.path.replace(/\*/g, '.*') + '$').test(req.path || ''),
        )[0];
      } catch (e) {}

It's defined on my end unless I'm missing something?

@SDAdham
Copy link
Author

SDAdham commented Jul 13, 2021

@sbarbat I think the error happens here:

engine
                .render(renderOptions)
                .then(html => {
                  console.log('render result', html);
                  if (!routeCache.isCacheableValue || routeCache.isCacheableValue(req.originalUrl, req)) {
                    memoryCache
                      .set(cacheKey, html, routeCache.ttl ?? 60)
                      .catch((err: Error) => console.log('Could not cache the request', err));
                  }

                  callback(null, html);
                })
                .catch(callback); // the error happens from this callback

I'm not sure if this is related to the import:

import { CommonEngine } from '@nguniversal/common/engine';
// import { ɵCommonEngine as CommonEngine } from '@nguniversal/common/​engine';

@shyamal890
Copy link

@sbarbat I am also facing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants