๐Ÿž[BUG]: Error: You have forgotten to import the NGXS module!

See original GitHub issue

Affected Package

@ngxs/store

Is this a regression?

Donโ€™t know. First time Iโ€™m seeing it.

Description

My server side rendered Angular 11 app exhibits a strange behavior where if Iโ€™m sending many concurrent requests (like via a benchmark or a SEO crawler), it would start throwing ERROR Error: You have forgotten to import the NGXS module! errors in some of my components that use my stores. If Iโ€™m just opening the page in the browser or sending a โ€œslowโ€ benchmark it works fine.

At first I thought itโ€™s because of my lazy loaded modular stores but then I reverted to an older commit with a monolith architecture and it exhibits the same behavior when multiple fast requests are hammering the app.

๐Ÿ”ฌ Minimal Reproduction

  1. Install Angular and NGXS
  2. Access an NGXS getter via @Select() in some component
  3. Setup server side rendering with nguniversal
  4. Send many concurrent requests for the page that accesses the NGXS store

๐Ÿ”ฅ Exception or Error

ERROR Error: You have forgotten to import the NGXS module!
    at createSelectObservable (/path/to/my/app/dist/my-app/server/main.js:159278:15)
    at GuideCategoriesComponent.get [as categories$] (/path/to/my/app/dist/my-app/server/main.js:159349:68)
    at GuideCategoriesComponent_Template (/path/to/my/app/dist/my-app/server/main.js:255335:142)
    at executeTemplate (/path/to/my/app/dist/my-app/server/main.js:74219:9)
    at refreshView (/path/to/my/app/dist/my-app/server/main.js:74088:13)
    at refreshComponent (/path/to/my/app/dist/my-app/server/main.js:75254:13)
    at refreshChildComponents (/path/to/my/app/dist/my-app/server/main.js:73885:9)
    at refreshView (/path/to/my/app/dist/my-app/server/main.js:74138:13)
    at refreshEmbeddedViews (/path/to/my/app/dist/my-app/server/main.js:75208:17)
    at refreshView (/path/to/my/app/dist/my-app/server/main.js:74112:9)

ERROR Error: You have forgotten to import the NGXS module!
    at createSelectObservable (/path/to/my/app/dist/my-app/server/main.js:159278:15)
    at GuidePostComponent.get [as categories$] (/path/to/my/app/dist/my-app/server/main.js:159349:68)
    at GuidePostComponent.get postCategory$ [as postCategory$] (/path/to/my/app/dist/my-app/server/main.js:258896:81)
    at GuidePostComponent_div_0_Template (/path/to/my/app/dist/my-app/server/main.js:258857:154)
    at executeTemplate (/path/to/my/app/dist/my-app/server/main.js:74219:9)
    at refreshView (/path/to/my/app/dist/my-app/server/main.js:74088:13)
    at refreshEmbeddedViews (/path/to/my/app/dist/my-app/server/main.js:75208:17)
    at refreshView (/path/to/my/app/dist/my-app/server/main.js:74112:9)
    at refreshComponent (/path/to/my/app/dist/my-app/server/main.js:75254:13)
    at refreshChildComponents (/path/to/my/app/dist/my-app/server/main.js:73885:9)

Environment

Libs:

Browser:

  • Screaming Frog Spider Crawler version 14.3
  • Chrome (desktop) version 89.0.4389.90
  • Chrome (Android) version XX
  • Chrome (iOS) version XX
  • Firefox version 85.0.2
  • Safari (desktop) version 14.0.3
  • Safari (iOS) version XX
  • IE version XX
  • Edge version XX

For Tooling issues:

  • Node version: v14.4.0
  • Platform: macOS 11.2.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
MaximeKoitsalucommented, Aug 12, 2022

Thanks for the reply, it turned out to be an issue with path mapping in tsconfig.json. Using explicit imports and avoiding shortened imports solved the underlying issue for my team.

1reaction
iangellacocommented, Jun 15, 2022

anyone solve this issue already ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

You've forgotten to import "NgxsSelectSnapshotModule" // the ...
The root cause of this issue is this file: https://github.com/ngxs/store/blob/master/packages/store/src/decorators/select/select-factory.ts.
Read more >
ngxs - Bountysource
๐Ÿž [BUG]: 'Error: You have forgotten to import the NGXS module' after upgrading to 3.7.4 $ 0. Created 5 months ago in ngxs/store...
Read more >
Unit Testing - NGXS
To perform a unit test we just dispatch the events, listen to the changes and perform our expectation. A basic test looks like...
Read more >
Ngxs App Initializer - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >
State Management in Angular Using NGXS - Auth0
We will look at how you can use NGXS to manage your application's state by ... Import the NgxsReduxDevtoolsPluginModule in our AppModule andย ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found