wooorm / refractor

Lightweight, robust, elegant virtual syntax highlighting using Prism
MIT License
722 stars 33 forks source link

Error: Unexpected token in `character-entities-legacy` when using this module #15

Closed scottwhudson closed 5 years ago

scottwhudson commented 5 years ago

I'm building a React library using create-react-library, and I'm getting an error that tracks back to refractor when trying to install a package (react-syntax-highlighter) that depends on refractor.

My error looks like this:

rollup v0.64.1
bundles src/index.js → dist/index.js, dist/index.es.js...
[!] Error: Unexpected token
node_modules/character-entities-legacy/index.json (2:9)
1: {
2:   "AElig": "Æ",
            ^
3:   "AMP": "&",
4:   "Aacute": "Á",

I've tried uninstalling, deleting node_modules and reinstalling the package twice with no success.

I've consulted all of my usual resources to resolve this without any success. Am I missing something here?

wooorm commented 5 years ago

The problem is probably your webpack config. The issue is similar to https://github.com/syntax-tree/hast-util-sanitize/pull/1#issuecomment-238027874. Could you try that, and see if that works?

scottwhudson commented 5 years ago

Yep, adding the json plugin to my rollup config solved the issue. I totally wouldn't have guessed that.

Thank for the tip!

flamincode commented 4 years ago

Yep, adding the json plugin to my rollup config solved the issue. I totally wouldn't have guessed that.

Thank for the tip!

Hi Scott. What should I put in rollup config exactlty?

flamincode commented 4 years ago

Nevermind, I figured it out by npm installing @rollup/plugin-json and then adding that to my rollup config. As you mentioned. Thanks for the help.