Encountering a compilation error when implementing ActionReducerMap in combination with StoreModule.forFeature

In my Angular project, the structure is organized as follows:

/(root or repo folder)
 |_ projects
    |_ mylib (main library to be exported from the repo)
    |_ sample-app (created for testing 'mylib' project in other projects)

To manage application state, I am using ngRx with Angular8.2.5, ngRx 8.3.0, and RxJs 6.5.3.

When running npm start, the 'sample-app' project starts while 'mylib' project is lazily loaded.

Here is how I set up the app store/state:

In sample-app/app.module.ts:

StoreModule.forRoot({}, {
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true,
        strictStateSerializability: true,
        strictActionSerializability: true,
      },
    }),
!environment.production ? StoreDevtoolsModule.instrument({ name: 'My Sample App' }) : [],

In mylib/mylib.module.ts:

import { libReducer} from './shared/store/lib.store';
StoreModule.forFeature('libState', libReducer)

The issue arises during the project build process when using ng build.

Error message:

https://i.sstatic.net/1KpZL.png

Logs do not provide much insight into the error.

The problem gets resolved if changing the definition inside mylib.module.ts to:

StoreModule.forFeature('libState', subFeatureOneReducer)

I prefer to keep all reducers in one place and only reference StoreModule.forFeature once within 'mylib' project.

Looking for guidance on setting up store/reducers correctly to resolve the build error.

Answer №1

Check out my revised code below, including the essential ROOT_REDUCERS element

export const ROOT_REDUCERS = new InjectionToken<
  ActionReducerMap<State, Action>
>("Root reducers token", {
  factory: () => ({
    router: fromRouter.routerReducer
  })
});

StoreModule.forRoot(ROOT_REDUCERS, {
    metaReducers,
    runtimeChecks: {
    strictStateImmutability: true,
    strictActionImmutability: true
    }
}),

To see the complete implementation, visit this link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preventing me from instantiating objects

I've been struggling with an issue for a while now consider the following: export abstract class abstractClass { abstract thing(): string } export class c1 extends abstractClass { thing(): string { return "hello" } } export cla ...

What is the best approach for managing validations on a field-by-field basis within a Formik FieldArray?

Scenario: When there are 3 participants, each participant will receive a set of questions. However, the display of each question is dependent on a list of "applied tickets" associated with the question. TLDR; I need to understand: if it's possible ...

What is the best way to implement the settimeout method in react?

I need assistance on how to effectively utilize the setTimeout() method in my code. Specifically, I am looking to trigger a click event on an element after a certain delay and execute a function afterwards. Here is the current implementation of my code: ...

Retrieving HTML content from Wikipedia's API using JavaScript

I am encountering an issue where every time I attempt to log data to my console, an error occurs. Could someone kindly point out what may be the problem with the code? My objective is to actually showcase the html content on a webpage. Below is the code ...

I keep encountering an issue with npm where it is unable to identify the executable to run whenever I launch VS Code and attempt to use Cypress

Whenever I open Visual Studio Code and try to run 'npx open cypress', I keep encountering this message in my terminal: npm ERR! could not determine executable to run Oddly enough, running 'npx cypress -v' provides version details, so ...

Persistent hover effect for collapsible accordion panels when closing them

My simple accordion features a functionality where a class of .open is added to the title + content group when you open a panel for styling purposes. Everything works smoothly, but I've noticed on my phone that after clicking to close a panel, the hov ...

Resolving the Duplicate Identifier Issue in Ionic 2 with Firebase Integration

I'm struggling with setting up ionic2 + Firebase 3. Following a tutorial, I installed Firebase and Typings using the commands below: npm install firebase --save npm install -g typings typings install --save firebase However, when I try to run ioni ...

Issue with window.getSelection() function in Mozilla Firefox

I have implemented code to retrieve the window.getSelection() and assign it to a variable in order to store the current focusNode and offset when the contenteditable div onBlur event is triggered. This functionality works as expected in the Chrome browse ...

TypeScript operates under the assumption that every key will be present on a Record object

Check out this code snippet: declare const foo: Record<string, number> const x = foo['some-key'] TypeScript indicates that x is of type number. It would be more accurate to say x is of type number | undefined, as there is no guarantee th ...

What is the best way to extract text following a particular symbol in javascript or Jquery?

If I have a string that reads and the cow went @moo, and my goal is to exclusively choose "moo"... what steps should I take? ...

When the tooltip component is triggered in a React application, the cursor is automatically directed to

I have been working on creating an input field that allows users to enter time as input. Here's the code snippet I am using: <InputMask mask="99:99" onBlur={handleOnBlur} onChange={(e) => { const ...

Storing HTML elements in a database using jQuery's html() method

I have encountered a dilemma that has left me stumped after extensive online research. I have a dynamically generated webpage and need to save the entire appended body of the page to a database using PHP and MySQL. My current approach involves using the fo ...

Creating an element in react-draggable with two sides bound and two sides open - here's how!

At the moment, I am facing an issue where the element is restricted from moving outside of the container with the class of card-width-height. My goal is to have the right and bottom sides bounded within the container while allowing the element to move beyo ...

Vue alert - Cannot access indexOf property of a value that is undefined

After browsing through numerous similar issues on StackOverflow, none seem to address the specific problem I encountered... I have been smoothly working on a Vue JS project + Laravel until I suddenly encountered an error that seems unsolvable (even though ...

Having trouble resolving a component from a component library while utilizing NPM link

My React application is set up with Create React App and a separate component library. I'm currently experimenting with using 'npm link' to test changes in the component library directly on my local machine. To achieve this, I first run &ap ...

Using jQuery to bind the "CTRL+A" key combination to exclusively selecting a specific region

My goal is to modify the CTRL+A shortcut so that instead of selecting all text, it will only select specific content within containers with a class of xyz. Unfortunately, I have not been successful in getting this functionality to work. Even attempting to ...

Exploring JavaScript functions within the Rails 4 asset pipeline directory

I am facing an issue while trying to use a JavaScript function through the Chrome Console after embedding that function within the Rails Asset Pipeline Manifest. To achieve this, I followed these steps to create and set up a basic Rails 4.2.4 App: $ rails ...

Ways to position a button at the bottom of a Bootstrap card

In the card layout, I am struggling to position the red button at the bottom of the column despite using margin auto. Can anyone provide a solution for this issue? Thank you in advance! <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a ...

Passing a Value from Child to Parent Function in Meteor: A Complete Guide

I am trying to pass the value of a result from a child element to its parent element. Initially, I used Session.set and Session.get which worked fine but I realize that using Sessions globally is not considered good practice. So, I attempted to utilize rea ...

SignalR 2.2 users are experiencing a lack of message reception

I have developed a unique self-hosted SignalR application that is operating within the framework of a console application. To access the hubs within this application, I have implemented a wrapper class to avoid referencing the SignalR.Core assemblies direc ...