guess-js / guess

🔮 Libraries & tools for enabling Machine Learning driven user-experiences on the web
https://guess-js.github.io/
MIT License
7.07k stars 203 forks source link

If app-routing isn't in same dir as app.module, guess errors on it's lazily loaded routes. #345

Open aaronfrost opened 4 years ago

aaronfrost commented 4 years ago

If my project looks like this:

- app.module.ts
- routing
    |- app-routing.module.ts

And in the app-routing I have routes that are lazily loaded, when I do the traverseForRoutes stuff... it errors on the lazily loaded modules in the app-routing. If I move the file back to the same dir as the app.module... the error goes away.

mgechev commented 4 years ago

It'll be helpful if you can provide a tiny repro so I can play around with it over the weekend.

aaronfrost commented 4 years ago

This is a good point. Let me see if I can get something together for you.

suke commented 3 years ago

Hi, I created a demo app that reproduces this problem. It also includes a script to run guess-parser node ./scripts/routes.js.

mgechev commented 3 years ago

Thank you @suke, I'll make some time for this issue in the next a couple of days.

rhutchison commented 3 years ago

I can confirm I'm also seeing an issue with path resolution. lmk if you need additional details, but it sounds like the same issue.

Error: The relative path "../../collections/collections-routing.module" to "C:\Websites\gym.com\apps\gym\src\app\app.module.ts" cannot be resolved to a module
    at Object.exports.getModulePathFromRoute (C:\Websites\gym.com\node_modules\guess-parser\dist\guess-parser\index.js:334:15)
    at Object.exports.getRoute (C:\Websites\gym.com\node_modules\guess-parser\dist\guess-parser\index.js:570:34)
    at C:\Websites\gym.com\node_modules\guess-parser\dist\guess-parser\index.js:558:28
    at Array.map (<anonymous>)
    at Object.exports.getRoute (C:\Websites\gym.com\node_modules\guess-parser\dist\guess-parser\index.js:554:14)
    at C:\Websites\gym.com\node_modules\guess-parser\dist\guess-parser\index.js:938:34
    at visitTopLevelRoutes (C:\Websites\gym.com\node_modules\guess-parser\dist\guess-parser\index.js:909:13)
    at visitNodes (C:\Websites\gym.com\node_modules\typescript\lib\typescript.js:27858:30)
    at Object.forEachChild (C:\Websites\gym.com\node_modules\typescript\lib\typescript.js:28032:24)
    at NodeObject.forEachChild (C:\Websites\gym.com\node_modules\typescript\lib\typescript.js:146142:23)
AlexAegis commented 3 years ago

I encountered the problem too, and explored it a little further, for example in the case of nested lazy modules. Please check the description of this issue: https://github.com/scullyio/scully/issues/1347