Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw new Error('load must pass a non-empty string'); after upgrading to 7.x #690

Closed
genox opened this issue Nov 14, 2022 · 7 comments
Closed

Comments

@genox
Copy link

genox commented Nov 14, 2022

馃悰 Bug Report

I was using 6.x and upgraded to 7.x, now I get this error when trying to run i18next from a package.json script:

node_modules/lilconfig/dist/index.js:80
        throw new Error('load must pass a non-empty string');
              ^

Error: load must pass a non-empty string

I checked the changelog and edited defaultValue accordingly, but the error didn't change.

Here's my config:

module.exports = {
  contextSeparator: '_',
  // Key separator used in your translation keys

  createOldCatalogs: false,
  // Save the \_old files

  defaultNamespace: 'common',
  // Default namespace used in your i18next config

  defaultValue: (locale, namespace, key, value) => {
    return key;
  },
  // Default value to give to empty keys
  // You may also specify a function accepting the locale, namespace, and key as arguments

  indentation: 2,
  // Indentation of the catalog files

  keepRemoved: false,
  // Keep keys from the catalog that are no longer in code

  keySeparator: false,
  // Key separator used in your translation keys
  // If you want to use plain english keys, separators such as `.` and `:` will conflict. You might want to set `keySeparator: false` and `namespaceSeparator: false`. That way, `t('Status: Loading...')` will not think that there are a namespace and three separator dots for instance.

  // see below for more details
  lexers: {
    hbs: ['HandlebarsLexer'],
    handlebars: ['HandlebarsLexer'],

    htm: ['HTMLLexer'],
    html: ['HTMLLexer'],

    mjs: ['JavascriptLexer'],
    js: ['JavascriptLexer'], // if you're writing jsx inside .js files, change this to JsxLexer
    ts: ['JavascriptLexer'],
    jsx: ['JsxLexer'],
    tsx: ['JsxLexer'],

    default: ['JavascriptLexer'],
  },

  lineEnding: 'auto',
  // Control the line ending. See options at https://github.com/ryanve/eol

  locales: ['de'],
  // An array of the locales in your applications

  namespaceSeparator: false,
  // Namespace separator used in your translation keys
  // If you want to use plain english keys, separators such as `.` and `:` will conflict. You might want to set `keySeparator: false` and `namespaceSeparator: false`. That way, `t('Status: Loading...')` will not think that there are a namespace and three separator dots for instance.

  output: 'public/locales/$LOCALE/$NAMESPACE.json',
  // Supports $LOCALE and $NAMESPACE injection
  // Supports JSON (.json) and YAML (.yml) file formats
  // Where to write the locale files relative to process.cwd()

  pluralSeparator: '_plural_',
  // Plural separator used in your translation keys
  // If you want to use plain english keys, separators such as `_` might conflict. You might want to set `pluralSeparator` to a different string that does not occur in your keys.

  input: ['src/**/*.{js,ts,tsx}'],
  // An array of globs that describe where to look for source files
  // relative to the location of the configuration file

  sort: true,
  // Whether or not to sort the catalog. Can also be a [compareFunction](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#parameters)

  verbose: true,
  // Display info about the parsing including some stats

  failOnWarnings: true,
  // Exit with an exit code of 1 on warnings

  failOnUpdate: true,
  // Exit with an exit code of 1 when translations are updated (for CI purpose)

  customValueTemplate: null,
  // If you wish to customize the value output the value as an object, you can set your own format.
  // ${defaultValue} is the default value you set in your translation function.
  // Any other custom property will be automatically extracted.
  //
  // Example:
  // {
  //   message: "${defaultValue}",
  //   description: "${maxLength}", // t('my-key', {maxLength: 150})
  // }

  resetDefaultValueLocale: null,
  // The locale to compare with default values to determine whether a default value has been changed.
  // If this is set and a default value differs from a translation in the specified locale, all entries
  // for that key across locales are reset to the default value, and existing translations are moved to
  // the `_old` file.

  i18nextOptions: null,
  // If you wish to customize options in internally used i18next instance, you can define an object with any
  // configuration property supported by i18next (https://www.i18next.com/overview/configuration-options).
  // { compatibilityJSON: 'v3' } can be used to generate v3 compatible plurals.

  yamlOptions: null,
  // If you wish to customize options for yaml output, you can define an object here.
  // Configuration options are here (https://github.com/nodeca/js-yaml#dump-object---options-).
  // Example:
  // {
  //   lineWidth: -1,
  // }
};

To Reproduce

Not sure if this is reproducible on a new install.

Your Environment

  • runtime version: nodejs 18
  • i18next version: 7.0.0
  • os: Mac
@stasbamiza
Copy link

Had the same error. Temporarily switched back to the 6.6.0. After switching to the previous version, everything works like a charm.

@SteveBruntwood
Copy link

Same issue with v7.

Replaced useKeysAsDefaultValue: true with defaultValue: (locale, namespace, key, value) => value ? value : ${key}

Switched back to 6.6.0 with useKeysAsDefaultValue: true fixed issue.

@karellm
Copy link
Member

karellm commented Nov 14, 2022

This is related to the support of multiple file format for the config. Can you tell me which command you use and whether you have a config file or not?

@karellm
Copy link
Member

karellm commented Nov 14, 2022

I've published 7.0.2, can you please try it and if it still doesn't work, share the command you run and whether you have a config file or not.

@Zerebokep
Copy link

Doesn't seem to fix the issue:

node:internal/errors:484
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:393:5)
    at validateString (node:internal/validators:163:11)
    at Object.resolve (node:path:1102:7)
    at file:///redacted/node_modules/i18next-parser/bin/cli.js:139:40
    at Array.map (<anonymous>)
    at file:///redacted/node_modules/i18next-parser/bin/cli.js:131:26 {
  code: 'ERR_INVALID_ARG_TYPE'
}

config:

  output: `${localePath}/$LOCALE/$NAMESPACE.${localeExtension}`,
  input: './src/**/*.{ts,tsx}',

I'm using yarn i18next to run the parser.

@karellm
Copy link
Member

karellm commented Nov 14, 2022

@Zerebokep Please try 7.0.3 and if it doesn't work, I'd need to know what the yarn i18next actually does in your package.json.

@Zerebokep
Copy link

That did the job, thank you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants