chrisguttandin / angular-prerender

A command line tool to prerender Angular Apps.
MIT License
125 stars 7 forks source link

Issue with i18n #89

Closed keserwan closed 4 years ago

keserwan commented 4 years ago

Hi @chrisguttandin, Thank you again for your great contributions. Sorry to bother you again, I found an issue when you build the project with multi locale (i18n). You can check this demo project also to reproduce the issue (I pushed the last changes that you fixed in https://github.com/chrisguttandin/angular-prerender/issues/87):

https://github.com/keserwan/testAngularPrerender

To reporduce it, you run the following commands: 1) npm i 2) npm run build:i18n-ssr 3) npx angular-prerender

npm run build:i18n-ssr: this command will create 2 folders "ar" and "en" in "dist/website/server" and "dist/website/browser".

I am getting this error after calling "npx angular-prerender" Knowing that main.js is not available in "dist/website/server", it is available in the two folders "en" and "ar".

(node:26332) UnhandledPromiseRejectionWarning: Error: Cannot find module 'C:\Development\test\testPrerender\dist\website\server\main'
Require stack:
- C:\Development\test\testPrerender\node_modules\angular-prerender\build\node\functions\prerender.js
- C:\Development\test\testPrerender\node_modules\angular-prerender\build\node\app.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at prerender (C:\Development\test\testPrerender\node_modules\angular-prerender\build\node\functions\prerender.js:74:7)
    at C:\Development\test\testPrerender\node_modules\angular-prerender\build\node\app.js:78:3
(node:26332) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:26332) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
PS C:\Development\test\testPrerender> 
chrisguttandin commented 4 years ago

Hi @keserwan,

you don't bother me at all. I'm happy that you discover all those unsupported edge cases (and that you report them so nicely).

I guess you run ng build with the --configuration flag set to 'production-ar' or 'production-en' respectively, right?

ng build --configuration=production-ar

Currently angular-prerender only support to set the --browser-target but it doesn't allow to specify the configuration. I wonder if it would make sense to support something like this:

npx angular-prerender --configuration=production-ar

What do you think?

keserwan commented 4 years ago

Yes I think passing the configuration parameter is what we need.

chrisguttandin commented 4 years ago

Hi @keserwan, I just published v4.2.0 which supports full target specifiers similar to the ng run command.

For your app the options do probably look like this:

npx angular-prerender --browser-target website:build:production-ar --server-target website:server:production-ar

I will close the issue now since I expect it work. But as always please feel free to reopen it if you notice any bugs.

keserwan commented 4 years ago

Great, I will check and let you know

keserwan commented 4 years ago

I updated to version 4.2.0 I got this error after calling: npx angular-prerender --browser-target website:build:production-ar --server-target website:server:production-ar

(node:15028) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:107:11)
    at join (path.js:372:7)
    at prerender (C:\Development\test\testPrerender\node_modules\angular-prerender\build\node\functions\prerender.js:70:35)
(node:15028) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15028) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I updated the test repo if you want to test with:

https://github.com/keserwan/testAngularPrerender

chrisguttandin commented 4 years ago

My bad, thanks for catching this bug. I just released v4.2.1. When I update angular-prerender to that version in your test repo it works.

I accidentally forgot to read the properties from the regular options in case they are not defined in the given configuration. This caused the error since the tsConfig property is defined as a regular option and is not overwritten in the configuration.

keserwan commented 4 years ago

with v4.2.1 it worked on the demo but not on my live project. I am getting another error now:


npx angular-prerender --browser-target website:build:production-ar --server-target website:server:production-ar
(node:25176) UnhandledPromiseRejectionWarning: Error: Cannot find source file for path: C:\Development\ABC-XYZ\ClientApps\node_modules\express\index.js
    at imports (C:\Development\ABC-XYZ\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:196:15)
    at C:\Development\ABC-XYZ\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:218:25
    at visitNodes (C:\Development\ABC-XYZ\ClientApps\node_modules\typescript\lib\typescript.js:16631:30)
    at Object.forEachChild (C:\Development\ABC-XYZ\ClientApps\node_modules\typescript\lib\typescript.js:16859:24)
    at SourceFileObject.NodeObject.forEachChild (C:\Development\ABC-XYZ\ClientApps\node_modules\typescript\lib\typescript.js:121410:23)
    at imports (C:\Development\ABC-XYZ\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:203:8)
    at C:\Development\ABC-XYZ\ClientApps\node_modules\guess-parser\dist\guess-parser\index.js:218:25
    at visitNodes (C:\Development\ABC-XYZ\ClientApps\node_modules\typescript\lib\typescript.js:16631:30)
    at Object.forEachChild (C:\Development\ABC-XYZ\ClientApps\node_modules\typescript\lib\typescript.js:16859:24)
    at SourceFileObject.NodeObject.forEachChild (C:\Development\ABC-XYZ\ClientApps\node_modules\typescript\lib\typescript.js:121410:23)
(node:25176) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25176) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
chrisguttandin commented 4 years ago

The error looks like something in your code is importing "express" and the parser can't find it. Is that possible?