ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8k stars 1.97k forks source link

ngrx/signals type error "Exported variable 'CounterStore' has or is using name 'STATE_SIGNAL' from external module "node_modules/@ngrx/signals/src/signal-state" but cannot be named" #4151

Closed urielzen closed 9 months ago

urielzen commented 9 months ago

Which @ngrx/* package(s) are the source of the bug?

signals

Minimal reproduction of the bug/regression with instructions

Copy the code from the ngrx/signals anouncement: Announcing NgRx v17: Introducing NgRx Signals

import { signalStore, withState } from '@ngrx/signals';

export const CounterStore = signalStore(withState({ count: 0 }));

image

Expected behavior

I am working in an Nx mono repo. If I add the store ts file directly in the app (apps folder), the error is not present. The error only happens when the file is created in an nx library (libs folder).

This works correctly. image

This does not work. image

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

ngrx/signals: v17.0.0 Angular: v17.0.1 Nx: v17.1.2 Node: v18.17.1

Other information

No response

I would be willing to submit a PR to fix this issue

markostanimirovic commented 9 months ago

Related to https://github.com/microsoft/TypeScript/issues/37888

As a workaround, you can set declarations to false in the library's tsconfig if it's not buildable.

francobasilico commented 9 months ago

Related to microsoft/TypeScript#37888

As a workaround, you can set declarations to false in the library's tsconfig if it's not buildable.

@markostanimirovic Will this be a problem for buildable libs?

markostanimirovic commented 9 months ago

Related to microsoft/TypeScript#37888 As a workaround, you can set declarations to false in the library's tsconfig if it's not buildable.

@markostanimirovic Will this be a problem for buildable libs?

Yes, because they need declarations.

In the meantime, I found a workaround for this bug. PR with the fix will be raised soon.

brandonroberts commented 9 months ago

Marko's fix has been released with 17.0.1 on npm

elite-benni commented 9 months ago

I just wanted to mention my mistake, because I got the same error when refactoring from a component-store to signalstore. Maybe it helps someone, because it was a tricky one to find, as the error appears on the store class and not on the return.

When I transferred some updaters I once forgot to change the return into patchstate. return { ...store, counter:1}; to patchState(store, { counter:1 });

If a function, that is returned by withMethods, returns the store, this leads to the same error.

rhutchison commented 5 months ago

The issue exists if you're also trying to extend a store:

image

export function createExtendedStore() {
  const Store = signalStore(withState({ foo: 'bar' }));

  @Injectable()
  class ExtendedStore extends Store {}

  return ExtendedStore;
}

We will try to determine if it makes sense to open a feature request or if we can do some other workaround.

matheo commented 1 month ago

+1 I'm experiencing this in v18.0.2

I've disabled the declaration and declarationMap of my tsconfig.lib.json in the meantime.

rainerhahnekamp commented 1 month ago

@matheo, @rhutchison, thanks for reporting. Since extending classes seems to be a new error, I've opened a new issue in #4489

ghost commented 4 weeks ago

@matheo @rhutchison I've found yet another workaround - you can give it a shot https://github.com/ngrx/platform/issues/4489#issuecomment-2291133015