i18next / i18next-scanner

Scan your code, extract translation keys/values, and merge them into i18n resource files.
http://i18next.github.io/i18next-scanner
MIT License
560 stars 129 forks source link

Unable to parse Trans component #158

Open bgold0 opened 5 years ago

bgold0 commented 5 years ago

I get a lot of these errors when I run i18n-scanner.

i18next-scanner: Unable to parse Trans component from "/directory/index.js" Error: acorn-private-class-elements requires acorn@^6.1.0, not 5.7.3

Anyone know how to fix them? this wasn't always the case.

Version

Configuration

{
    input: [
        'src/**/*.{js,jsx}',
        // Use ! to filter out files or directories
        '!src/**/*.spec.{js,jsx}',
        '!src/i18n/**',
        '!**/node_modules/**'
    ],
    output: './',
    options: {
        sort: true,
        debug: true,
        func: {
            list: ['t'],
            extensions: ['.js', '.jsx']
        },
        trans: {
            component: 'Trans',
            i18nKey: 'i18nKey',
            defaultsKey: 'defaults',
            extensions: ['.js', '.jsx'],
            fallbackKey: function(ns, value) {
                return value;
            },
            acorn: {
                ecmaVersion: 10, // defaults to 10
                sourceType: 'module' // defaults to 'module'
                // Check out https://github.com/acornjs/acorn/tree/master/acorn#interface for additional options
            }
        },
        lngs: ['en'],
        ns: ['common', 'translations'],
        defaultNs: 'common',
        removeUnusedKeys: true,
        keySeparator: '||',
        nsSeparator: '::',
        interpolation: {
            escapeValue: false,
            formatSeparator: ',',
            prefix: '{{',
            suffix: '}}'
        },
        defaultLng: 'en',
        defaultValue: function(lng, ns, key) {
            return key;
        },
        resource: {
            loadPath: 'public/static/locales/{{lng}}/{{ns}}.json',
            savePath: 'public/static/locales/{{lng}}/{{ns}}.json',
            jsonIndent: 2,
            lineEnding: '\n'
        }
    }
}
tobiasweibel commented 5 years ago

I just resolved such a problem in a private repository. Basically the underlying acorn-jsx was using acorn 6.2.0 and i18next-scanner was using acron 6.3.0. When it parsed code, especially the closing slash (e.g. </div>), it compared two different TokenType.slash instances because each acorn version created it's own TokenTypes. The result of the comparison was never equal. Code pointer: acorn-jsx/index.jsx, method jsx_parseElementAt(...) line if (this.eat(tt.slash)) { was false all the time.

In my package.json file I'm overwriting the acorn version now manually by doing

  "resolutions": {
    "acorn": "^6.3.0"
  },

I'm now unsure where to fix the versioning problem. Maybe i18next-scanner could add a resolutions entry to package.json.

I'm using yarn to install node modules. Maybe that could be relevant as well.

jgerigmeyer commented 4 years ago

I'm hitting this too. It'd be great if we could get a new release that uses acorn v7?

bgold0 commented 4 years ago

@tobiasweibel Not sure how that fixed it but but when I added the resolutions I'm still getting the error.

tobiasweibel commented 4 years ago

My current resolutions definition is

  "resolutions": {
    "**/acorn-jsx/**/acorn": "^6.3.0",
    "**/eslint/**/acorn": "^7.0.0",
    "acorn": "^6.3.0"
  },

But that works only with yarn. This is of course only a workaround and I'm not totally sure how to resolve that issue properly. Most probably moving i18next-scanner to acorn 7 would solve it for now.

yanickrochon commented 4 years ago

Just got the same problem :

i18next-scanner: Unable to parse Trans component from "/home/user/path/to/project/src/index.js"
    Error: acorn-private-class-elements does not support mixing different acorn copies
...

This message appears for all files in my project.

cheton commented 4 years ago

@bryan-opslock @jgerigmeyer @yanickrochon

This might work for some people:

  1. Upgrade npm to the latest version.

    $ npm i -g npm
  2. Remove node_modules and package-lock.json, then do a fresh install.

    $ rm -rf node_modules package-lock.json
    $ npm i
  3. Run npm ls to see the package dependencies. Make sure only acorn@6.3.0 package is installed, and all other ones are deduped, like below:

    $ npm ls | grep acorn@6
    │ │ ├── acorn@6.3.0 deduped
    │ ├── acorn@6.3.0
    │ ├── acorn@6.3.0 deduped
rwieruch commented 4 years ago

Fresh installation of i18next-scanner and react-i18next and I run into the same problem. Solutions from this thread didn't help so far.

ramiel commented 4 years ago

Any news on this?

marpe commented 4 years ago

Running into the same issue here :(

alxscms commented 4 years ago

Same issue

samuliasmala commented 4 years ago

I have the same issue, first I get

i18next-scanner: Unable to parse Trans component from "/home/vagrant/kehu/client/index.js"
Error: acorn-private-class-elements requires acorn@^6.1.0, not 2.7.0

errors for all files. After running npm install --save-dev acorn@6.1.0 the error changes to

Error: acorn-private-class-elements does not support mixing different acorn copies

I have done fresh install and it didn't help. Any suggestions where to start solving the issue?

genesiscz commented 4 years ago

+1

azakharo commented 3 years ago

+1

cutterbl commented 2 years ago

I fixed my issues by adjusting my options

{
  options: {
    // ...
    trans: {
      // ...
      acorn: {
        ecmaVersion: 2020 // default is 10, so must override
      }
    }
}