NuxtJS与UglifyJS和node-rsa的构建中断。我该如何解决?

时间:2019-02-14 06:34:43

标签: node.js webpack nuxt.js uglifyjs

我正在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找到解决方案)来暂时缓解该问题,但这似乎不是一个长期解决方案。解决此问题的正确方法是什么?

可能相关的问题:Webpack breaks when i include node-rsa library

1 个答案:

答案 0 :(得分:1)

问题是我试图在浏览器上使用节点库(而不是uglify安全)而不进行网络打包。我转而使用纯JS来满足加密需求,一切都很好。