i18next-scanner icon indicating copy to clipboard operation
i18next-scanner copied to clipboard

Unable to parse Trans component

Open bgold0 opened this issue 4 years ago • 14 comments

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

  • i18next: 17.0.11
  • i18next-scanner: 2.10.2

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'
		}
	}
}

bgold0 avatar Aug 13 '19 21:08 bgold0

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.

tobiasweibel avatar Aug 19 '19 11:08 tobiasweibel

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

jgerigmeyer avatar Sep 04 '19 18:09 jgerigmeyer

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

bgold0 avatar Sep 05 '19 13:09 bgold0

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.

tobiasweibel avatar Sep 06 '19 06:09 tobiasweibel

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.

yanickrochon avatar Sep 19 '19 19:09 yanickrochon

@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 [email protected] package is installed, and all other ones are deduped, like below:

    $ npm ls | grep acorn@6
    │ │ ├── [email protected] deduped
    │ ├── [email protected]
    │ ├── [email protected] deduped
    

cheton avatar Sep 21 '19 08:09 cheton

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

rwieruch avatar Feb 04 '20 10:02 rwieruch

Any news on this?

ramiel avatar Feb 07 '20 15:02 ramiel

Running into the same issue here :(

marpe avatar Mar 25 '20 09:03 marpe

Same issue

alxscms avatar Mar 30 '20 17:03 alxscms

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 [email protected] 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?

samuliasmala avatar Apr 17 '20 19:04 samuliasmala

+1

genesiscz avatar May 08 '20 17:05 genesiscz

+1

azakharo avatar Oct 16 '20 16:10 azakharo

I fixed my issues by adjusting my options

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

cutterbl avatar Mar 03 '22 19:03 cutterbl