ngneat / until-destroy

🦊 RxJS operator that unsubscribe from observables on destroy
https://netbasal.com/
MIT License
1.74k stars 100 forks source link

Should main and module field values in package.json be switched? #22

Closed jeffmath closed 5 years ago

jeffmath commented 5 years ago

In my project which employs Babel, Jest tests which passed before I started using your package are now failing with a message indicating that the code from your package is not plain JavaScript. In your package.json, the module field is set to "dist/es5/index.js", which I believe uses CommonJS modules, while main is set to "dist/index.js", which employs standard JavaScript modules. Reading this proposal describing how the module field allows opt-in use of standard JavaScript modules (while still providing access to CommonJS modules through main), I feel that these two field values should be switched. And indeed, when I switch them, my tests pass again.

jeffmath commented 5 years ago

I should mention that I really like the benefits that ngx-take-until-destroy provides, and am thankful that you created it.

NetanelBasal commented 5 years ago

Switched to ng-packger. Everything should be standard now. (v5.2.0)

NetanelBasal commented 5 years ago

5.2.1

jeffmath commented 5 years ago

I get this error now when running an ng build -prod using 5.2.1:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'C:\Users\Jeff\KBRA\Spectre\spectre-ui\src'
ERROR in Error: Metadata version mismatch for module C:/Users/Jeff/KBRA/Spectre/spectre-ui/node_modules/ngx-take-until-destroy/ngx-take-until-destroy.d.ts, found version 4, expected 3
    at StaticSymbolResolver.getModuleMetadata (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:25616:34)
    at StaticSymbolResolver._createSymbolsOf (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:25404:46)
    at StaticSymbolResolver.getSymbolsOf (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:25385:14)
    at C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:24241:30
    at Array.forEach (<anonymous>)
    at extractProgramSymbols (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:24240:79)
    at AotCompiler.analyzeModulesAsync (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:23796:47)
    at CodeGenerator.codegen (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler-cli\src\codegen.js:32:14)
    at Function.NgTools_InternalApi_NG_2.codeGen (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@angular\compiler-cli\src\ngtools_api.js:73:30)
    at _donePromise.Promise.resolve.then (C:\Users\Jeff\KBRA\Spectre\spectre-ui\node_modules\@ngtools\webpack\src\plugin.js:430:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

A non-prod build works fine.

jeffmath commented 5 years ago

Changing the "version" value in ngx-take-until-destroy.metadata.json from 4 to 3 fixes the error in the prod build. I'm not sure if that is the right way to fix it, though.

NetanelBasal commented 5 years ago

I can't reproduce this. Can you try delete node modules and re-install it?

jeffmath commented 5 years ago

I tried your suggestion but am still getting the same error for the prod build.

NetanelBasal commented 5 years ago

Oh, it's because you are on v5.

NetanelBasal commented 5 years ago

Try v5.2.2, please.

jeffmath commented 5 years ago

5.2.2 fixes the problem with the prod build. Thank you!