docusaurus: Adding scala to additionalLanguages in prism breaks Docusaurus V2

🐛 Bug Report

Prerequisites

  • I’m using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io
  • I have read the console error message carefully (if applicable)

Description

Adding scala to additionalLanguages in prism breaks Docusaurus V2.

Have you read the Contributing Guidelines on issues?

Yes I have.

Steps to reproduce

Use https://new.docusaurus.io to create a CodeSandbox reproducible demo of the bug.

(Write your steps here:)

  1. Open the docusaurus.config.js file.
  2. Add the following prism setting to right below foot (just the same as the default structure of the config generated by npx @docusaurus/init@latest init website classic)
    prism: {
        additionalLanguages: ["scala"]
    }
    
  3. Save
  4. The result on the right-hand side is just a blank page.

Steps to reproduce on the local environment

Additional instructions to reproduce on the local machine,

  1. Create a new Docusaurus V2 site
    npx @docusaurus/init@latest init website classic
    cd website
    npm start
    
  2. Acess http://localhost:3000 to Make sure the website is fine.
  3. Open the docusaurus.config.js file
    vim docusaurus.config.js
    
  4. Add the following additionalLanguages to prism.
    prism: {
      additionalLanguages: ['scala'],
    },
    
  5. Start the Docusaurus again
    npm start
    
  6. Acess http://localhost:3000 again
  7. Get the blank page.

NOTE: npm start on the console shows no error

npm start

> website@0.0.0 start /private/tmp/docs/website
> docusaurus start

Starting the development server...
Docusaurus website is running at "http://localhost:3000/".

✔ Client
  Compiled successfully in 1.65s

ℹ 「wds」: Project is running at http://localhost:3000/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /private/tmp/docs/website
ℹ 「wds」: 404s will fallback to /index.html

Expected behavior

Just a normal Docusaurus V2 website when accessing http://localhost:3000

Actual behavior

A blank page when accessing http://localhost:3000

Chrome’s Developer Tools console shows this error. Screen Shot 2021-06-19 at 5 28 29 pm

Here is the downloaded log. localhost-1624087717210.log

Your environment

  • Public source code: Tested locally and it’s so easy to reproduce with the steps I provided.

  • Public site URL: Tested locally and it’s so easy to reproduce with the steps I provided.

  • Node Environment

    $ npm --version
    6.14.11
    
    $ node --version
     v14.16.0
    
  • Chrome: 91.0.4472.106

  • Operating System: macOS Big Sur 11.4

  • Docusaurus version: 2.0.0-beta.1

Reproducible demo

Use https://new.docusaurus.io to create a CodeSandbox reproducible demo of the bug.

https://codesandbox.io/s/happy-hugle-q0kr8?file=/docusaurus.config.js:1975-2026

(Paste the link to an example repo, including a docusaurus.config.js, and exact instructions to reproduce the issue.)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (7 by maintainers)

Most upvoted comments

You can sort after adding the missing languages to the array 😄

Honestly what I care about is the unit tests, there’s not a single way to implement this.

Oh, right, sorry about that, I totally forgot to test the presence of one of the two. It’s what I get for responding to discussion threads late at night 😅

As for the sorting approach, after revisiting it in a less fleeting manner, I realized it wouldn’t be that much cleaner since it would only work if both languages are already present in the array.

Anyway, I feel think this is a good starting point. I’ll see if I can submit a proper patch soon.

Honestly, Joi is a pain to work with 😅

I don’t really care which API of it you use as long as I can clearly see unit tests passing and covering the functionality you implement, including coverage for the language ordering for all kinds of inputs.

Note: if the order matters you’d rather define ordering rules instead of push/unshift, and also cover the case where user provides additionalLanguages: ["scala","java"] or additionalLanguages: ["php","markup-templating"]