Skip to content

You've forgotten to import "NgxsSelectSnapshotModule" // the NGXS module #103

Description

@elegon32

Description

We see in our server logs many of these 2 FATAL Errors on production and on non-production environments:

  • FATAL [main.js:xx] NgxsSelectSnapshotModuleIsNotImported [Error]: You've forgotten to import "NgxsSelectSnapshotModule"! at assertDefined (/opt/app/dist/server/main.js:xx:yy) at getStore
  • FATAL [main.js:xx] Error: You have forgotten to import the NGXS module! at createSelectObservable (/opt/app/dist/server/main.js:1:yy)

We clearly have imported both ngxs modules in AppModule and in the Feature Modules.
In App module:


NgxsModule.forRoot(
      [
      xxx....
      ],
      {
        developmentMode: !environment.production,
      },
    ),
    NgxsRouterPluginModule.forRoot(),
    NgxsFormPluginModule.forRoot(),
    NgxsSelectSnapshotModule.forRoot(),
    NgxsStoragePluginModule.forRoot({
         ...xxx
      },
    }),
    NgxsReduxDevtoolsPluginModule.forRoot({
      name: 'xxxx',
      disabled: environment.production,
    }),

in Feature Module:


    NgxsModule.forFeature([xxx, yyy]),
    NgxsSelectSnapshotModule,

It is a very huge project with many modules and components... And the errors are only happening via SSR, and there it happens rarely on our dev machines... When it does, though, we see a LOT of Error statements successively while no other component or module is complaing with an error. It is just ngxs.
It seems, that SSR still deliveres the html, and the Angular app loads still well on the client (including all ngxs stuff)

🔬 Minimal Reproduction

Ok. We found out how to reproduce:

  1. open a page in browser
  2. refresh
  3. quickly abort loading
  4. quickly refresh again
  5. --> many many FATAL Errors

Guess: This might be caused by angular destroying all stuff and both ngxs modules will clear the Injector onDestroy.
As the errors happens ONLY when we reload quickly after aborting (just aborting never creates the errors), it must be sth about angular universal still (re-?) using some components while ngxs already got rid of its injector reference.

🔥 Exception or Error


FATAL [main.js:2897] NgxsSelectSnapshotModuleIsNotImported [Error]: You've forgotten to import "NgxsSelectSnapshotModule"! 
at assertDefined (/opt/app/dist/server/main.js:2897:xx) 
at getStore (/opt/app/dist/server/main.js:2897:xx) 
at XXXComponent.get [as isXXX] (/opt/app/dist/server/main.js:2897:xx) 
at XXXComponent_Template (/opt/app/dist/server/main.js:2897:xx) 
at executeTemplate (/opt/app/dist/server/main.js:2897:xx) 
at refreshView (/opt/app/dist/server/main.js:2897:xx) 
at refreshComponent (/opt/app/dist/server/main.js:2897:xx) 
at refreshChildComponents (/opt/app/dist/server/main.js:2897:xx) 
at refreshView (/opt/app/dist/server/main.js:2897:xx) 
at refreshComponent (/opt/app/dist/server/main.js:2897:xx)

or....

FATAL [main.js:2897] Error: You have forgotten to import the NGXS module! 
at createSelectObservable (/opt/app/dist/server/main.js:1:xx) 
at AppComponent.get [as progress] (/opt/app/dist/server/main.js:1:xx) 
at AppComponent_Template (/opt/app/dist/server/main.js:2897:1625353) 
at executeTemplate (/opt/app/dist/server/main.js:2897:xx) 
at refreshView (/opt/app/dist/server/main.js:2897:xx) 
at refreshComponent (/opt/app/dist/server/main.js:2897:xx) 
at refreshChildComponents (/opt/app/dist/server/main.js:2897:xx) 
at refreshView (/opt/app/dist/server/main.js:2897:xx) 
at renderComponentOrTemplate (/opt/app/dist/server/main.js:2897:xx)
at tickRootContext (/opt/app/dist/server/main.js:2897:xx)

Environment


Libs:
    "@angular/core": "^11.0.6",
    "@ngxs/store": "^3.7.1",
    "@ngxs-labs/select-snapshot": "^2.0.1",

Browser: only on SSR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions