-
Notifications
You must be signed in to change notification settings - Fork 91
Can't use npm package in Typescript and Webpack project #93
Comments
Having the same issue while updating from v0.11.1 to v.1.1.3. Trying to import in a few different ways: import {Jose} from "jose-jwe-jws";
import * as Jose from "jose-jwe-jws";
import Jose from "jose-jwe-jws"; All turn out with |
v0.11.1 works when I import and use as such: import * as Jose from 'jose-jwe-jws'
const cryptographer = new Jose.Jose.WebCryptographer() I need to update to the latest version since snyk.io has found vulnerabilities in lodash.merge@4.6.1 in v0.11.1 |
Seems that the issue lies in the webpack configuration:
using
Pull #89 does some changes in regards to this. Can this be looked at, right now this configuration doesn't allow using the library as a node module or a ES6 module. |
#89 has conflicts. If it builds, I'm happy to merge it. |
Let me suggest a PR for this. |
Thank you for your feedback. I've already headed to this configuration:
and also tried:
installing npm package from Thanks. |
Yeah, my attempts have proved that we would need to tweak the definition file... And I end up having issues with decryption on that new package. Let me know if you end up with a solution. |
I have resorted to use version 0.1.6 where I can use it like this in my TS project. import * as Jose from 'jose-jwe-jws'
const cryptographer = new Jose.Jose.WebCryptographer() |
We're seeing the same issue here. Just like @wfortin, only 0.1.6. works were as 0.1.7 fails. |
Also, added jest testing framework and first unit test to improve coverage.
Also, added jest testing framework and first unit test to improve coverage.
@damnhandy @wfortin this should be fixed in 0.2.0 |
@mbyczkowski care to give an example with 0.2.0? I still end up with an object that contains almost nothing when importing in all these different ways: import {Jose} from "jose-jwe-jws";
import * as Jose from "jose-jwe-jws";
import Jose from "jose-jwe-jws"; Seems that the TS definitions are fixed now, but at runtime I get: import * as Jose from "jose-jwe-jws"; import {Jose} from "jose-jwe-jws"; import Jose from "jose-jwe-jws"; I get the error So it seems the webpack configuration is still incorrect, as the object is defined but the exported methods are not in that object. So I'm still sticking to 0.1.6 as mentionned here |
I've added a codesandbox to replicate the issue here: v0.2.0 (not working as described in my last comment) : https://codesandbox.io/s/hopeful-mirzakhani-2m2bz?fontsize=14 v0.1.6 (working) : https://codesandbox.io/s/jose-jwe-jws020-0w7y9?fontsize=14 Hope this helps! |
@wfortin thanks for the repro. I'm going to look into this. |
This should address issues seen in #93.
This should address issues seen in #93.
Changed the library type to UMD. > libraryTarget: 'umd' - This exposes your library under all the module definitions, allowing it to work with CommonJS, AMD and as global variable. from https://webpack.js.org/configuration/output/#outputlibrarytarget
I've submitted a pull request that allows me to import it in my Angular 8 application, satisfying the Typescript + Webpack problem. UMD library packaging should allow it to continue to be used as a var, but also an importable module. |
Anyone else still struggling with this, I was able to workaround the issue by directly importing the non-minified JS files. All the contained paths there were relative, so webpack was able to figure out how to wire this all together ok from that. E.g., I've made a file called
Once that is done, I simply import that somewhere, and things work! |
* Fix #93. I can use the NPM package in a Typescript/Webpack project Changed the library type to UMD. > libraryTarget: 'umd' - This exposes your library under all the module definitions, allowing it to work with CommonJS, AMD and as global variable. from https://webpack.js.org/configuration/output/#outputlibrarytarget
Indeed it works as expected with this last commit, when do you plan a new release with corresponding npm package as well ? Thx. |
I have just released 0.2.2. @mbelge feel free to re-open the issue if you're still seeing the problem in the latest release. |
Hi,
I'm trying to use the library in my project, based on Typescript targeting es6 and using commonjs modules. The final output is produced using Webpack and targeting the web platform.
I've installed the dependency with npm:
and try to reference it in my code:
Everything compiles good, but when I run the result of webpack in my page, I've got an error:
I've got the same error trying to run tests with Mocha... :-(
What I'm missing?
Thank You
The text was updated successfully, but these errors were encountered: