rnadler / ng2-password-strength-bar

Angular 2/4/5 Password Strength Bar
http://bobonmedicaldevicesoftware.com/blog/2016/12/09/publishing-an-angular-2-component-npm-package/
MIT License
20 stars 17 forks source link

Uncaught Error: Unexpected value 'PasswordStrengthBar' declared by the module 'AppModule' #1

Closed Priyesha closed 7 years ago

Priyesha commented 7 years ago

Versions. angular-cli: 1.0.0-beta.15 node: 5.0.0 os: win32 x64

I am trying to use 'ng2-password-strength-bar' in my application. When i try to import it in my app.module.ts file:

import { PasswordStrengthBar } from "ng2-password-strength-bar";

@NgModule({ declarations: [ AppComponent, PasswordStrengthBar]

it is giving me following runtime error (no compile time error):

Uncaught Error: Unexpected value 'PasswordStrengthBar' declared by the module 'AppModule' at http://localhost:4200/main.bundle.js:28457:31 at Array.forEach (native) at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/main.bundle.js:28444:49) at RuntimeCompiler._compileComponents (http://localhost:4200/main.bundle.js:44967:47) at RuntimeCompiler.compileModuleAndComponents (http://localhost:4200/main.bundle.js:44905:37) at RuntimeCompiler.compileModuleAsync (http://localhost:4200/main.bundle.js:44896:21) at PlatformRef.bootstrapModuleWithZone (http://localhost:4200/main.bundle.js:30834:25) at PlatformRef.bootstrapModule (http://localhost:4200/main.bundle.js:30816:21) at Object. (http://localhost:4200/main.bundle.js:62874:124) at __webpack_require__ (http://localhost:4200/inline.js:53:30)

rnadler commented 7 years ago

@Priyesha, If there are no errors on the package import the only thing I can think to do is re-install. Try:

$ rm -rf ./node_modules/ng2-password-strength-bar $ npm update

Then re-start the application.

Priyesha commented 7 years ago

@rnadler I tried re-installing it, but i am still seeing the same issue at runtime.

alechemy commented 7 years ago

I'm getting precisely the same error

rnadler commented 7 years ago

Can either of you please provide an example project that exhibits this problem? Without being able to reproduce the issue it is difficult to identify the root cause. Thanks!

karolmie1 commented 7 years ago

[WORKAROUND] Copy the passwordStrengthBar.ts file and put in in your project. Don't forget about the license notice!

I would guess that the problem is that you are not exporting module, but class.

I've experienced the same problem. When I've simply copy/pasted your code it worked, so it's definitively problem with packaging.

export * might also be a problem, I've seen it cause trouble with webpack. export { classname } would be better. That is probably not the cause thought.

I can provide a way to reproduce, but unfortunately my projects is bit far from minimal example, https://bitbucket.org/kmierzej/fragaria-webapp/branch/reproduce-ng2-password-strength-bar You would also have to run https://bitbucket.org/kmierzej/fragaria-server, then login as admin/admin and go to Ustawienia page (and look at the sea of read in dev console). 2 terminals, in one ./gradlew run, in other yarn start, or npm run start.

In settings.module.ts you can flip the imports, to see that it is working. In the same file you'll find an example on how to export component inside module.