wishtack / wishtack-steroids

Frontend on Steroids: Reactive Component Loader, RxJS Scavenger...
https://wishtack.io
MIT License
96 stars 16 forks source link

[esnext] tsconfig.server.json remove "module":"commonjs" issue #195

Open AmaelN opened 4 years ago

AmaelN commented 4 years ago

Hi,

Using commonjs, there is not isssue. Everything is working fine

I've spent the morning on this issue and I've created a sample to reproduce the issue:

When I remove the "module":"commonjs" from tsconfig.server.js from tour of heroes

"compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    //"module": "commonjs",
    "types": []
  },

It will use by default "esnext" module

and include a hello world wt-lazy and add it to the app.component.ts then npm run build:ssr

.html

<wt-lazy [location]="helloLocation"
         [inputs]="{name:'World'}"></wt-lazy>

app.component.ts

helloLocation = {
        moduleId: 'wt-hello',
        selector: 'app-hello'
    };

app.module.ts

 imports: [
...
 ReactiveComponentLoaderModule.forRoot(),
        ReactiveComponentLoaderModule.withModule({
            moduleId: 'wt-hello',
            loadChildren: () => import('src/app/hello/hello.module').then(m => m.HelloModule)
        }),
]

under dist/server/, i will find a file name hello-hello-module-ngfactory.js

If I run the server with node dist/server

I will get the following error

Running on the server with appId=tour-of-heroes
ERROR TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (C:\dev\test\universal\dist\server.js:69485:30)
    at Function.requireEnsure [as e] (C:\dev\test\universal\dist\server.js:69504
:25)
    at Object.ɵ0 [as loadChildren] (C:\dev\test\universal\dist\server.js:69819:3
8)
    at ReactiveComponentLoader.<anonymous> (C:\dev\test\universal\dist\server.js
:157144:65)
    at step (C:\dev\test\universal\dist\server.js:34967:23)
    at Object.next (C:\dev\test\universal\dist\server.js:34948:53)
    at C:\dev\test\universal\dist\server.js:34941:71
    at new ZoneAwarePromise (C:\dev\test\universal\dist\server.js:1068:33)
    at __awaiter (C:\dev\test\universal\dist\server.js:34937:12)
    at ReactiveComponentLoader._getModuleFactory (C:\dev\test\universal\dist\ser
ver.js:157133:71)

For the moment, I have a solution using commonjs module nevertheless whenever you have time it will be good to be able to use 'esnext'

Thanks in advance

AmaelN commented 4 years ago

I'm using "@wishtack/reactive-component-loader": "^1.1.1",