react-html-parser意外错误

时间:2017-03-02 12:00:52

标签: parsing reactjs html-parsing

我从后端传递html字符串以反应组件,我使用react-html-parser将我的html字符串转换为react组件。但是收到错误。

./~/entities/maps/entities.json中的错误 模块解析失败:/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/entities/maps/entities.json意外的令牌(1:9) 您可能需要适当的加载程序来处理此文件类型。 SyntaxError:意外的令牌(1:9)     在Parser.pp $ 4.raise(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:2221:15)     在Parser.pp.unexpected(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:603:10)     在Parser.pp.semicolon(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:581:61)     在Parser.pp $ 1.parseExpressionStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:966:10)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:730:24)     在Parser.pp $ 1.parseBlock(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:981:25)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:709:33)     在Parser.pp $ 1.parseTopLevel(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:638:25)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:516:17)     at Object.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:3098:39)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/Parser.js:902:15)     在DependenciesBlock。 (/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/NormalModule.js:104:16)     在DependenciesBlock.onModuleBuild(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)     at nextLoader(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5     在Storage.finished(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/graceful-fs/graceful-fs.js:78:16     在FSReqWrap.readFileAfterClose [as oncomplete](fs.js:445:3)  @ ./~/react-html-parser/~/htmlparser2/lib/Tokenizer.js 4:16-54

错误在./~/entities/maps/legacy.json中 模块解析失败:/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/entities/maps/legacy.json意外的令牌(1:9) 您可能需要适当的加载程序来处理此文件类型。 SyntaxError:意外的令牌(1:9)     在Parser.pp $ 4.raise(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:2221:15)     在Parser.pp.unexpected(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:603:10)     在Parser.pp.semicolon(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:581:61)     在Parser.pp $ 1.parseExpressionStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:966:10)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:730:24)     在Parser.pp $ 1.parseBlock(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:981:25)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:709:33)     在Parser.pp $ 1.parseTopLevel(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:638:25)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:516:17)     at Object.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:3098:39)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/Parser.js:902:15)     在DependenciesBlock。 (/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/NormalModule.js:104:16)     在DependenciesBlock.onModuleBuild(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)     at nextLoader(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5     在Storage.finished(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/graceful-fs/graceful-fs.js:78:16     在FSReqWrap.readFileAfterClose [as oncomplete](fs.js:445:3)  @ ./~/react-html-parser/~/htmlparser2/lib/Tokenizer.js 5:16-52

./~/entities/maps/xml.json中的错误 模块解析失败:/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/entities/maps/xml.json意外的令牌(1:6) 您可能需要适当的加载程序来处理此文件类型。 SyntaxError:意外的令牌(1:6)     在Parser.pp $ 4.raise(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:2221:15)     在Parser.pp.unexpected(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:603:10)     在Parser.pp.semicolon(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:581:61)     在Parser.pp $ 1.parseExpressionStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:966:10)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:730:24)     在Parser.pp $ 1.parseBlock(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:981:25)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:709:33)     在Parser.pp $ 1.parseTopLevel(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:638:25)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:516:17)     at Object.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:3098:39)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/Parser.js:902:15)     在DependenciesBlock。 (/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/NormalModule.js:104:16)     在DependenciesBlock.onModuleBuild(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)     at nextLoader(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5     在Storage.finished(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/graceful-fs/graceful-fs.js:78:16     在FSReqWrap.readFileAfterClose [as oncomplete](fs.js:445:3)  @ ./~/react-html-parser/~/htmlparser2/lib/Tokenizer.js 6:16-49

./~/entities/maps/decode.json中的错误 模块解析失败:/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/entities/maps/decode.json意外的令牌(1:4) 您可能需要适当的加载程序来处理此文件类型。 SyntaxError:意外的令牌(1:4)     在Parser.pp $ 4.raise(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:2221:15)     在Parser.pp.unexpected(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:603:10)     在Parser.pp.semicolon(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:581:61)     在Parser.pp $ 1.parseExpressionStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:966:10)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:730:24)     在Parser.pp $ 1.parseBlock(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:981:25)     在Parser.pp $ 1.parseStatement(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:709:33)     在Parser.pp $ 1.parseTopLevel(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:638:25)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:516:17)     at Object.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/acorn/dist/acorn.js:3098:39)     在Parser.parse(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/Parser.js:902:15)     在DependenciesBlock。 (/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack/lib/NormalModule.js:104:16)     在DependenciesBlock.onModuleBuild(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)     at nextLoader(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5     在Storage.finished(/Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)     at /Users/PrashantKumarKatariya/teabox_web/teabox_django/static/node_modules/graceful-fs/graceful-fs.js:78:16     在FSReqWrap.readFileAfterClose [as oncomplete](fs.js:445:3)  @ ./~/entities/lib/decode_codepoint.js 1:16-46

1 个答案:

答案 0 :(得分:0)

尝试添加Json加载程序。有同样的错误,这对我有用。 https://github.com/webpack-contrib/json-loader