jss icon indicating copy to clipboard operation
jss copied to clipboard

Setting the language to 'en' using the create-sitecore-jss CLI, causes a duplicate locale error.

Open liznelson opened this issue 1 year ago • 2 comments

Describe the Bug

When using the create-sitecore-jss cli to stand up a starter app, setting the language to 'en' causes a duplicate locale error that causes the site build to fail.

throw new Error(`Specified i18n.locales contains the following duplicate locales:\n` + `${[
 ^Error: Specified i18n.locales contains the following duplicate locales: en 
  Each locale should be listed only once.

The source of this error seems to be in packages/create-sitecore-jss/src/templates/nextjs-styleguide/src/lib/next-config/plugins/styleguide.js. The cli defined language is added with templating but there is no filter if the input is 'en'. This is the file code.


const styleguidePlugin = (nextConfig = {}) => {
  return Object.assign({}, nextConfig, {
    i18n: {
      ...nextConfig.i18n,
      locales: ['en', '<%- language %>'], 
    },
  });
};

To Reproduce

Install the starter template with style guide and define the language as -en.

npx create-sitecore-jss 
  --templates nextjs,nextjs-sxa,nextjs-styleguide,nextjs-styleguide-tracking 
  --appName locale-bug-repro 
  --fetchWith GraphQL 
  --prerender SSR 
  --language en 

Try building the application, you can use next:dev or one of the sitecore starting scripts.

You will see an error about duplicate locales. When inspecting the /lib/next-config/plugins/styleguide.js file, you will see locales: ['en', 'en'].

Expected Behavior

The language is filtered if 'en'.

Possible Fix

No response

Provide environment information

  • Sitecore Version:
  • JSS Version: 21.2.4
  • Browser Name and version:
  • Operating System and version (desktop or mobile):
  • Link to your project (if available):

liznelson avatar Aug 16 '23 05:08 liznelson

@liznelson Thanks for the detailed information. We have a ticket in our internal backlog and will work on this issue

illiakovalenko avatar Sep 12 '23 10:09 illiakovalenko