简体   繁体   中英

Webpack breaks when i include node-rsa library

When I try to include the node-rsa library with Webpack, as so:

import NodeRSA from 'node-rsa';

I get the following error:

ERROR in ./~/constants-browserify/constants.json
Module parse failed: /home/hencic00/Dropbox/Documents/Camelot/node_modules/constants-browserify/constants.json Unexpected token (2:12)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:12)
    at Parser.pp$4.raise (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp.semicolon (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:581:61)
    at Parser.pp$1.parseExpressionStatement (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:966:10)
    at Parser.pp$1.parseStatement (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:730:24)
    at Parser.pp$1.parseBlock (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:981:25)
    at Parser.pp$1.parseStatement (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:709:33)
    at Parser.pp$1.parseTopLevel (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:638:25)
    at Parser.parse (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:516:17)
    at Object.parse (/home/hencic00/Dropbox/Documents/Camelot/node_modules/acorn/dist/acorn.js:3098:39)
    at Parser.parse (/home/hencic00/Dropbox/Documents/Camelot/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (/home/hencic00/Dropbox/Documents/Camelot/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (/home/hencic00/Dropbox/Documents/Camelot/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/home/hencic00/Dropbox/Documents/Camelot/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /home/hencic00/Dropbox/Documents/Camelot/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (/home/hencic00/Dropbox/Documents/Camelot/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at /home/hencic00/Dropbox/Documents/Camelot/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
 @ ./~/node-rsa/src/NodeRSA.js 10:16-36

There doesn't seem to be any existing questions on this topic. Any ideas?

只需将json loader添加到您的webpack配置中即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM