NuxtJS 构建与 UglifyJS 和 node-rsa 中断。我该如何解决这个问题?

NuxtJS build breaks with UglifyJS and node-rsa. How do I resolve this?

我在 NuxtJS 项目中使用库 node-rsa (https://www.npmjs.com/package/node-rsa)。使用命令 nuxt build(默认情况下包括 JS 和 CSS 的缩小)构建生产环境时,构建过程在接近尾声时中断并显示以下消息:

ERROR in 0.nuxt.bundle.7c6932a7a42bdaaa7fa4.js from UglifyJs
Unexpected token: name (pem) [./~/node-rsa/src/formats/pkcs1.js:55,0][0.nuxt.bundle.7c6932a7a42bdaaa7fa4.js:42640,20]
Error: Webpack build exited with errors
    at /home/ubuntu/front-end/node_modules/nuxt/dist/nuxt.js:904:44
    at /home/ubuntu/front-end/node_modules/webpack/lib/Compiler.js:267:15
    at Compiler.emitRecords (/home/ubuntu/front-end/node_modules/webpack/lib/Compiler.js:362:37)
    at /home/ubuntu/front-end/node_modules/webpack/lib/Compiler.js:260:12
    at /home/ubuntu/front-end/node_modules/webpack/lib/Compiler.js:355:11
    at next (/home/ubuntu/front-end/node_modules/tapable/lib/Tapable.js:154:11)
    at Compiler.compiler.plugin (/home/ubuntu/front-end/node_modules/webpack/lib/performance/SizeLimitsPlugin.js:99:4)
    at Compiler.applyPluginsAsyncSeries1 (/home/ubuntu/front-end/node_modules/tapable/lib/Tapable.js:158:13)
    at Compiler.afterEmit (/home/ubuntu/front-end/node_modules/webpack/lib/Compiler.js:352:8)
    at Compiler.<anonymous> (/home/ubuntu/front-end/node_modules/webpack/lib/Compiler.js:347:14)
    at /home/ubuntu/front-end/node_modules/async/dist/async.js:460:16
    at iteratorCallback (/home/ubuntu/front-end/node_modules/async/dist/async.js:1034:13)
    at /home/ubuntu/front-end/node_modules/async/dist/async.js:944:16
    at /home/ubuntu/front-end/node_modules/graceful-fs/graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:117:15)

我可以通过禁用 uglifyJS(在 https://github.com/nuxt/nuxt.js/issues/250 找到解决方案)暂时缓解这个问题,但这似乎不是一个长期的解决方案。解决这个问题的正确方法是什么?

可能相关的问题:

问题是我试图在浏览器上使用节点库(不是 uglify-safe)而不对其进行 webpacking。我转而使用纯 JS 来满足我的加密需求,一切都很顺利。