ERROR in bundle.js from UglifyJs
bsanchezb opened this issue · 2 comments
I've got an error, by using the webcrypto lib in my VueJS-frontend project.
As I see the problem not in my code, because when I just import the library without any usage I obtain the same error.
WARNING in ./node_modules/@trust/webcrypto/src/algorithms/SupportedAlgorithms.js
84:22-60 Critical dependency: the request of a dependency is an expression
@ ./node_modules/@trust/webcrypto/src/algorithms/SupportedAlgorithms.js
@ ./node_modules/@trust/webcrypto/src/algorithms/index.js
@ ./node_modules/@trust/webcrypto/src/SubtleCrypto.js
@ ./node_modules/@trust/webcrypto/src/Crypto.js
@ ./node_modules/@trust/webcrypto/src/index.js
@ ./src/utils/cryptoUtils.js
@ ./src/store/auth/signup.js
@ ./src/store/index.js
@ ./src/main.js
ERROR in bundle.js from UglifyJs
Unexpected token: name (NotSupportedError) [./node_modules/@trust/webcrypto/src/errors/NotSupportedError.js:4,0][bundle.js:21390,6]
@bsanchezb it gives an error because it’s not for use in webpack. You have to exclude it (by adding it to the externals: section in the webpack config).
The whole point of this library is that it’s an exact duplicate of the browser’s WebCrypto api, except on the server side. But for webpacked apps, you dont need it (and can’t use it), and have to exclude it.
@bsanchezb So, specifically, anytime you use webcrypto
in any library you're planning to Webpack,
you have to make sure it appears in the externals:
section of your webpack config. (While you're at it, you also want to exclude the text-encoding
library, so that it can use the browser's native TextEncoder
object.)
Like this:
externals: [
'@trust/webcrypto': 'crypto',
'text-encoding': 'TextEncoder',
]
What that does is tell Webpack to not include the webcrypto
library, and substitute it for the browser's native crypto
object.