facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
55.38k stars 8.31k forks source link

prism.additionalLanguages broken in v2 #2564

Closed watzon closed 4 years ago

watzon commented 4 years ago

šŸ› Bug Report

themeConfig.prism.additionalLanguages seems to be broken in the most recent v2 alpha.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

Expected behavior

Things should build correctly and syntax highlighting should work with the requested language

Actual Behavior

The following error is shown in the teminal:

TypeError: Cannot read property 'originalSource' of undefined
    at getSourceById (/home/username/projectname/node_modules/react-dev-utils/evalSourceMapMiddleware.js:18:17)
    at handleWebpackInternalMiddleware (/home/username/projectname/node_modules/react-dev-utils/evalSourceMapMiddleware.js:37:22)
    at Layer.handle [as handle_request] (/home/username/projectname/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/username/projectname/node_modules/express/lib/router/index.js:317:13)
    at /home/username/projectname/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/username/projectname/node_modules/express/lib/router/index.js:335:12)
    at next (/home/username/projectname/node_modules/express/lib/router/index.js:275:10)
    at SendStream.error (/home/username/projectname/node_modules/serve-static/index.js:121:7)
    at SendStream.emit (events.js:315:20)
    at SendStream.error (/home/username/projectname/node_modules/send/index.js:270:17)
    at SendStream.onStatError (/home/username/projectname/node_modules/send/index.js:421:12)
    at next (/home/username/projectname/node_modules/send/index.js:735:16)
    at onstat (/home/username/projectname/node_modules/send/index.js:724:14)
    at FSReqCallback.oncomplete (fs.js:171:21)

Your Environment

Reproducible Demo

https://github.com/watzon/dousaurus-testapp

Literally a brand new app with the aforementioned section added to the config.

lex111 commented 4 years ago

I cannot reproduce with similar errors, but Crystal syntax highlighting really will not work like that, because you still need to include Ruby, because Crystal extends it's syntax (this is done in Prism)

- additionalLanguages: ['crystal'],
+ additionalLanguages: ['ruby', 'crystal'],
watzon commented 4 years ago

@lex111 I tried that as well. I still get the same error in the terminal, and in the browser console I get Error: Cannot find module './prism-ruby'.

watzon commented 4 years ago

Weird. It works when I deploy to zeit, just not locally. So it has to be a system issue.

watzon commented 4 years ago

Ok well I got it working locally. I was using asdf to version node, so I uninstalled the asdf node plugin and installed node using my system package manager. Now things work.

fdmmarshall commented 3 years ago

I am having a similar issue when trying to add 'sparql' to the additionalLanguages array. Below is the error I am receiving: Any advice would be greatly appreciated.


Uncaught TypeError: Cannot set property 'boolean' of undefined
    at Object.extend (index.js?4953:86)
    at eval (prism-sparql.js?7063:1)
    at Object../node_modules/prismjs/components/prism-sparql.js (main.js:362)
    at __webpack_require__ (runtime~main.js:36)
    at fn (runtime~main.js:340)
    at webpackContext (main.js:377)
    at eval (prism-include-languages.js?fcbd:6)
    at Array.forEach (<anonymous>)
    at prismIncludeLanguages (prism-include-languages.js?fcbd:6)
    at eval (prism-include-languages.js?67c1:6)
    at Module../node_modules/@docusaurus/theme-classic/lib/prism-include-languages.js (main.js:237)
    at __webpack_require__ (runtime~main.js:36)
    at fn (runtime~main.js:340)
    at eval (client-modules.js?5edc:1)
    at Module../.docusaurus/client-modules.js (main.js:23)
    at __webpack_require__ (runtime~main.js:36)
    at fn (runtime~main.js:340)
    at eval (client-lifecycles-dispatcher.js:5)
    at Module../node_modules/@docusaurus/core/lib/client/client-lifecycles-dispatcher.js (main.js:79)
    at __webpack_require__ (runtime~main.js:36)
    at fn (runtime~main.js:340)
    at eval (PendingNavigation.js:9)
    at Module../node_modules/@docusaurus/core/lib/client/PendingNavigation.js (main.js:63)
    at __webpack_require__ (runtime~main.js:36)
    at fn (runtime~main.js:340)
    at eval (App.js:14)
    at Module../node_modules/@docusaurus/core/lib/client/App.js (main.js:55)
    at __webpack_require__ (runtime~main.js:36)
    at fn (runtime~main.js:340)
    at eval (clientEntry.js:7)
    at Module../node_modules/@docusaurus/core/lib/client/clientEntry.js (main.js:87)
    at __webpack_require__ (runtime~main.js:36)
    at __webpack_exec__ (main.js:772)
    at main.js:773
    at Function.__webpack_require__.O (runtime~main.js:83)
    at main.js:774
    at webpackJsonpCallback (runtime~main.js:1313)
    at main.js:9``` 
slorber commented 3 years ago

For anyone having a similar problem.

Here's how to fix it for the sparql language:

The process should be similar to any language requiring extensions

fdmmarshall commented 3 years ago

@slorber, amazing. Many thanks!

afshinm commented 2 years ago

Fix for scala:

     prism: {
       additionalLanguages: ['java', 'scala'],
     },
dswiecki commented 2 years ago

In fact I needed to add this to work

       additionalLanguages: ['clike', 'java', 'scala'],
     }

because of

Prism.languages.java = Prism.languages.extend('clike', {
Josh-Cena commented 2 years ago

clike should be enabled by the renderer by default: https://github.com/FormidableLabs/prism-react-renderer/blob/4d8019490a3ad89c310d877a9ae3130084261bc9/src/vendor/prism/includeLangs.js#L9

Does it not work without that?

blacktop commented 1 year ago

Is there a fix for armasm ?

coswat commented 1 year ago

what about php guys ? its not working

franck-grenier commented 1 year ago

Same for me, PHP not working with error in console:

Uncaught Error: Cannot find module './prism-php.js'

My config:

prism: {
    theme: lightCodeTheme,
    darkTheme: darkCodeTheme,
    additionalLanguages: ['php'],
},

It seems to be a path problem since I do have the file node_modules/prismjs/components/prism-php.js.

coswat commented 1 year ago

@franck-grenier i solved the issue by restarting the devlopment server

waldyrious commented 5 months ago

Just in case someone else ends up here with the same issue that I had, I'll quote the comment from @ArthurFlag here:

I do not use scala anywhere, but your suggestion fixed it.

Indeed, I too don't use have any scala code blocks in my docs, but somehow adding scala to the additionalLanguages array fixed the TypeError: Cannot set properties of undefined (setting 'triple-quoted-string') error that I was having (which I assume is the same as the Cannot set property 'triple-quoted-string' of undefined error reported in #5013).