Errors during compilation in Angular 2 local storage due to the absence of an exported member

Hello, I could use some assistance. I'm currently working on enabling local storage access in Angular 2 with typescript. To achieve this, I've integrated the npm package angular2-localstorage into my project. Initially, I had the "Tour of Heroes" application from angular.io up and running, albeit with minimal styling. Following the guidelines outlined at https://www.npmjs.com/package/angular2-localstorage, I added the recommended code to my app.module.ts file. However, upon attempting to run the application using npm start, I encountered the following compilation errors:

node_modules/angular2-localstorage/LocalStorageEmitter.ts(46,9): error TS2305: Module '"/Users/joshuaforman/Documents/CodeCraft/a2quickstart/a2-angular/node_modules/@angular/core/src/facade/lang"' has no exported member 'Type'.
node_modules/angular2-localstorage/LocalStorageEmitter.ts(47,9): error TS2305: Module '"/Users/joshuaforman/Documents/CodeCraft/a2quickstart/a2-angular/node_modules/@angular/core/src/di"' has no exported member 'provide'.

You can access all the code for this project here: https://github.com/joshuaforman/angular2-quickstart

Furthermore, below is the complete app.module.ts file that I modified, resulting in the occurrence of these errors:

import { NgModule }       from "@angular/core";
import { BrowserModule }  from "@angular/platform-browser";
import { FormsModule }    from "@angular/forms";
import { HttpModule }    from "@angular/http";

// added for LocalStorage
// followed instructions here: https://www.npmjs.com/package/angular2-localstorage
import { LocalStorageService, LocalStorageSubscriber } from "angular2-localstorage/LocalStorageEmitter";

// Imports for loading & configuring the in-memory web api
import { InMemoryWebApiModule } from "angular2-in-memory-web-api";
import { InMemoryDataService }  from "./in-memory-data.service";

import { AppComponent }        from "./app.component";
import { HeroDetailComponent } from "./hero-detail.component";
import { HeroesComponent }     from "./heroes.component";
import { HeroService }         from "./hero.service";
import  { DashboardComponent } from "./dashboard.component";

import { routing } from "./app.routing";

@NgModule({
  imports: [
    BrowserModule,
    HttpModule,
    InMemoryWebApiModule.forRoot(InMemoryDataService),
    FormsModule,
    routing
  ],
  declarations: [
        AppComponent,
        HeroesComponent,
        HeroDetailComponent,
        DashboardComponent
  ],
  bootstrap:    [ AppComponent ],
  providers:    [
        HeroService,
        LocalStorageService // added for Local Storage
  ]
})
export class AppModule {
  // added for Local Storage
  constructor(storageService: LocalStorageService) {}
}

I've left a comment on each line I added for local storage implementation with the text "LocalStorage". If these three lines are commented out, the compilation and runtime proceed without issues.

Currently, my main goal is to successfully compile the project. Your help is greatly appreciated.

As a newcomer to stack, this is my first question on the platform. Having benefited from the knowledge shared here in the past, I strive to adhere to the community guidelines. Any constructive feedback on how I can improve my queries is welcome.

Answer №1

Angular2-LocalStorage is not receiving updates, so it's best to switch to a different library for now. My suggestion is to try out Angular2 Cool Storage

Answer №2

Make the following changes in "LocalStorageEmitter.ts" located in the node_module "angular2-localstorage"

import {Type} from "@angular/core/src/type";
import {Provider} from "@angular/core/src/di";
import {ComponentRef} from "@angular/core";

export function LocalStorageSubscriber(appPromise: Promise<ComponentRef<any>>) {
    appPromise.then((bla) => {
        bla.injector.get(<Type<any>>LocalStorageService);
    });
}

It worked for me...

For more information, visit: https://github.com/marcj/angular2-localstorage/issues/66

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

Which is better: Angular 2 dedicated cache service or embedded cache management?

Our current project involves implementing complex cache management logic within various http services such as EmployeeService and DepartmentService. What would be the most optimal choice? Integrating cache logic directly into the model service classes ...

Switching services in test cases with ReflectiveInjector

Can the provider be changed using ReflectiveInjector in the same context? I require B to utilize a different value for the second test. A & B are both services... let injector: ReflectiveInjector; beforeEach(() => { injector = ReflectiveInjec ...

The ngrx state remains hidden

I am working on abstracting the implementation details of my ngrx state by encapsulating it in a shared service class, in order to keep my components clean and organized. Here is an example service class that is registered in my app.module.ts providers @ ...

What is the alternative method for establishing a child formGroup within a parent formGroup without using the initializer function?

Can anyone help me with dynamically setting a property in my formGroup to another formGroup, essentially creating a child formGroup? // Example 1 var parent = this._formBuilder.group({ id: [''], child: this._formBuilder.group({ na ...

Tips for handling various HTTP requests until a response is received

For my application, I have a need to make multiple http calls before proceeding to create certain objects. Only after all the http requests have received responses from the servers can I process the results and construct my page. To handle this scenario, ...

The Influence of Getter Performance in Angular Templates

As I delve into an existing Angular application, I've noticed a pattern where values used in templates across many components are actually properties that are being accessed through getters and setters without any additional logic: <input type="nu ...

Tips for testing a void method using unit testing

I'm aiming to increase my code coverage by writing unit tests. I have a method that simply triggers a notification without needing a response. How can I write a unit test for it? public error(message?: any, ...optionalParams: any[]) { if (this.is ...

Asynchronous function in TypeScript is restricting the return type to only one promise type

Using node version 14.7.0, npm version 6.14.7, and typescript version 3.7.3. I have a function that interacts with a postgres database and retrieves either the first row it finds or all results based on a parameter. It looks something like this: async fet ...

Resizing cell height in an HTML table is not supported by Angular 5

In my angular application, I've implemented a component that represents a basic HTML table. However, I'm facing an issue with reducing the height of cells within the table. It seems like my CSS styling is not affecting the display as desired. He ...

The script resource is experiencing a redirect that is not permitted - Service Worker

I have integrated a Service Worker into my Angular application, and it works perfectly when running on localhost. However, when I attempt to deploy the code in a development or different environment, I encounter the following error: Service worker registra ...

Encountering [Object Object] within an angular2 app

https://i.stack.imgur.com/iceKH.pngI recently created an angular2 application using ngrx/effects for handling http calls. My reference point was an application on GitHub. However, I am facing an issue where the response from the HTTP call is not displaying ...

What is the method for obtaining a literal type through a function parameter to use as a computed property name?

Can you help me with this code snippet? const fn = (name: string) => { return { [name]: "some txt" }; }; const res = fn("books"); // books or any other string The type of res recognized by TS is: const res: { [x: string]: string ...

The e2e Protractor test is unable to identify the Angular component within a complex Angular router with multiple layers

I am currently working on an Angular application and I need to set up end-to-end testing for this project. Angular Package: 4.6.6 Protractor: 5.3.0 In addition, my project includes a multi-layer router that wraps the router-outlet into another component ...

Obtaining data from a BehaviorSubject for numerous dynamically generated components

As I work on developing a dynamic preview feature, I'm experimenting with drag-and-drop functionality to generate components in a canvas. These components can be duplicated within the same canvas, and upon dropping them, settings like styling are appl ...

Fetching a collection from Cloud Firestore using Angular and Firebase

I'm looking to figure out how to retrieve lists from cloud firestore. Here is how I upload a list : export interface Data { name: string; address: string; address2: string; pscode: string; ccode: string; name2: string; } constructor(pri ...

When using Framer Motion for page transitions alongside React Router DOM v6, the layout components, particularly the Sidebar, experience rerenders when changing pages

After implementing page transitions in my React app using Framer Motion and React-Router-DOM, I noticed that all layout components such as the sidebar and navbar were unexpectedly rerendering upon page change. Here's a snippet of my router and layout ...

The View is not reflecting changes in the Variable

Is there a way to disable all the buttons when selectedplace is null in the Dialog, as it currently works when the Dialog first starts but remains activated all the time when the option is changed? I have attempted the following: Customized HTML: ...

How to easily update a URL string in Angular 5 router without altering the state of the application

I am working on an Angular 5 application that utilizes the angular router. The majority of my entry route components are placed under a context id, which represents a name in the app store along with other relevant data for that context. Even though the na ...

Why is it that PowerShell cannot execute Angular commands?

Recently, I started diving into Angular and encountered an issue using PowerShell in Windows. Every time I run an angular command like: ng new new-app or ng serve I keep getting this error message: ng : File C:\Users\< username >\ ...

The Updating Issue: Angular 2 Table Fails to Reflect Value Changes

I have initialized a table with user details using the ngOnInit() method. When I click on the "create user" button, it opens a form to add a new user to the database. However, the table does not update automatically with the new user's information. H ...