maciejtreder / ng-toolkit

:star: Angular tool-box! Start your PWA in two steps! Add Serverless support for existing projects and much more
https://www.angular-universal-pwa.maciejtreder.com
MIT License
1.12k stars 157 forks source link

node dist/prerender.js gives ReferenceError: <SomeComponent> is not defined (Components defined in routing.module.ts) #613

Open ank1106 opened 5 years ago

ank1106 commented 5 years ago

I'm submitting a...


[] Bug report  
[ ] Feature request
[x] Documentation issue or request

In package


[ ] @ng-toolkit/init
[ ] @ng-toolkit/serverless
[x] @ng-toolkit/universal
[ ] @ng-toolkit/pwa
[ ] @ng-toolkit/firebug

Current behavior

when I run npm run build:prerender then without app.routing.module it works fine but with having routing.module file gives an error of undefined component.

Minimal reproduction of the problem with instructions

create a new angular app 1.) ng new some-app 2.) choose yes for routing 3) run ng add @ng-toolkit/universal 4) then do npm run build:prerender

it will work fine now 5) create a component let say 'SomeComponent' and add it to app-routing.module 6) run step 4.) it will give below error

undefined:4 component:SomeComponent ^

ReferenceError: SomeComponent is not defined at eval (eval at (/home/ankush/makerobos/test-app/dist/prerender.js:119382:45), :4:15) at /home/ankush/makerobos/test-app/dist/prerender.js:119382:45 at Array.forEach () at /home/ankush/makerobos/test-app/dist/prerender.js:119361:49 at Array.forEach () at /home/ankush/makerobos/test-app/dist/prerender.js:119353:49 at visitNode (/home/ankush/makerobos/test-app/dist/prerender.js:135564:24) at Object.forEachChild (/home/ankush/makerobos/test-app/dist/prerender.js:135866:24) at NodeObject.module.exports.NodeObject.forEachChild (/home/ankush/makerobos/test-app/dist/prerender.js:236085:23) at /home/ankush/makerobos/test-app/dist/prerender.js:119349:65 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test-app@0.0.0 build:prerender: npm run build:prod && node dist/prerender.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the test-app@0.0.0 build:prerender script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/ankush/.npm/_logs/2019-05-14T11_20_39_598Z-debug.log

Example repository

link to repo having this issue -> https://github.com/ank1106/ssr-test

marcocoelho commented 5 years ago

I'm going through a similar problem.

It runs all the process arrives at the end it displays the following message:

`WARNING in ./node_modules/typescript/lib/typescript.js 90061:19-45 Critical dependency: the request of a dependency is an expression @ ./prerender.ts fs.js:122 throw err; ^

Error: ENOENT: no such file or directory, open 'src/./app/../../shared-module/shared.module.ts' at Object.openSync (fs.js:443:3) at Object.readFileSync (fs.js:348:35) at D:\Projetos_Front\Marketplace.UI\dist\prerender.js:151189:40 at Array.forEach () at findRoutes (D:\Projetos_Front\Marketplace.UI\dist\prerender.js:151188:21) at D:\Projetos_Front\Marketplace.UI\dist\prerender.js:151189:26 at Array.forEach () at findRoutes (D:\Projetos_Front\Marketplace.UI\dist\prerender.js:151188:21) at D:\Projetos_Front\Marketplace.UI\dist\prerender.js:151189:26 at Array.forEach ()`