i18next-scanner
i18next-scanner copied to clipboard
Unable to parse Trans component
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'
}
}
}
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.
I'm hitting this too. It'd be great if we could get a new release that uses acorn v7?
@tobiasweibel Not sure how that fixed it but but when I added the resolutions
I'm still getting the error.
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.
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.
@bryan-opslock @jgerigmeyer @yanickrochon
This might work for some people:
-
Upgrade npm to the latest version.
$ npm i -g npm
-
Remove node_modules and package-lock.json, then do a fresh install.
$ rm -rf node_modules package-lock.json $ npm i
-
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
Fresh installation of i18next-scanner
and react-i18next
and I run into the same problem. Solutions from this thread didn't help so far.
Any news on this?
Running into the same issue here :(
Same issue
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?
+1
+1
I fixed my issues by adjusting my options
{
options: {
// ...
trans: {
// ...
acorn: {
ecmaVersion: 2020 // default is 10, so must override
}
}
}