Skip to content
New issue

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

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ignore files inside node_modules #196

Closed
wuifdesign opened this issue Aug 5, 2021 · 6 comments · Fixed by #215
Closed

ignore files inside node_modules #196

wuifdesign opened this issue Aug 5, 2021 · 6 comments · Fixed by #215

Comments

@wuifdesign
Copy link

Describe the bug

Plugin should ignore files inside "node_modules", or at least have a setting for this.

How to reproduce

Import a package which uses t functions. ex: @reduxjs/toolkit, react-i18next

Expected behavior

Ignore files inside "node_modules"

What actually happens

Displays a warning:

babel-plugin-i18next-extract: Extraction error in /node_modules/@reduxjs/toolkit/node_modules/immer/dist/immer.esm.js at line 1. Couldn't evaluate i18next key. You should either make the key evaluable or skip the line using a skip comment (/* i18next-extract-disable-line */ or /* i18next-extract-disable-next-line */).

Your environment

  • OS (e.g. ArchLinux): Mac
  • Plugin version (e.g. 0.3.0): 0.8.3
  • Node version (e.g. 12.13.0): 12
@wuifdesign wuifdesign changed the title Ignore files inside node_modules ignore files inside node_modules Aug 5, 2021
@kennethlynne
Copy link

We hit this today. Did you find a solution for this?
It is an issue with libs like formik and dayjs too

@kennethlynne
Copy link

Our current workaround looks like this:

module.exports = function (api) {
  api.cache(true)

  return {
    plugins: [
      // workaround for https://github.com/gilbsgilbs/babel-plugin-i18next-extract/issues/196
      // to only enable it when we try to extract translations in a script and control the input, and not in the context of a bundler (metro etc)
      ...(process.env.EXTRACT_TRANSLATIONS === 'true'
        ? [
            [
              'i18next-extract',
              {
                locales: ['en', 'nb'],
                outputPath: 'src/translations/{{locale}}/translation.json',
                defaultValue: '',
                defaultContexts: [''],
                discardOldKeys: true,
              },
            ],
          ]
        : []),
    ],
  }
}

Then we're able to do stuff like this

 "translations:extract-keys": "cross-env EXTRACT_TRANSLATIONS=true yarn babel 'src/**/*.{js,jsx,ts,tsx}' --ignore '**/*.test.ts','**/*.test.tsx'",

@juliosampaio
Copy link

Same issue here :( Having a setting for this would be nice.

@hirbod
Copy link

hirbod commented Feb 8, 2022

@gilbsgilbs are you still maintaining this library? I get like thousands of error logs because it tries to search for a billion keys inside of node_modules

@gilbsgilbs
Copy link
Owner

@hirbod if you submit a PR, I'll gladly review, merge and publish a new release. I can't do it myself yet though, sorry.

@hirbod
Copy link

hirbod commented Feb 8, 2022

Alright, thanks for your quick response. I'll try to see if I can exclude node_modules somehow. I just spent the whole day forking three different repos and I am investing more time fixing stuff than actually working currently :D

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
5 participants