Recyclerlistview: SyntaxError: Unexpected token import

Created on 8 May 2018  路  6Comments  路  Source: Flipkart/recyclerlistview

Jest Test Suite fails to run.
Does the module need any Babel presets _"es2015, react, stage-0,1?"_ / plugins, when building with webpack. (currently only react-native & react-native-web are present)

Dev builds go through absolutely fine, but the test's fail at ->
unexpected token import from lodash-es\debounce

```
node_modules\recyclerlistview\node_modules\lodash-es\debounce.js:1
({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import isObject from './isObject.js';
^^^^^^

SyntaxError: Unexpected token import
at new Script (vm.js:51:7)
at Object. (node_modules/recyclerlistview/dist/web/core/RecyclerListView.js:41:18)

important bits of package.json:

"webpack-dev-server": "2.8.2",
"webpack": "3.5.1",

"react": "16.3.2",
"react-native": "0.55.3",
"react-native-web": "0.6.1",

"recyclerlistview": "1.3.4"

"transformIgnorePatterns": [
"[/\\]node_modules[/\\].+\.(js|jsx)$"
],
```

If the issue is missing something important, hit me up.

Most helpful comment

Our solution to this issue:

We added recyclerlistview to the transformIgnorePatterns property of jest.config.js. This appears to be properly transpiling things now.

jest.config.js:

module.exports = {
...
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!react-native|react-navigation|lodash-es|recyclerlistview)',
  ],
...
}

All 6 comments

Could be related to lodash-es being in es6. I think I missed that fact. You can just pass it through the transpile process as well to fix this.

I'm getting a very similar error when testing the recyclerlistview. Is there something I'm missing?

Error

Test suite failed to run

/Users/*****/*****/node_modules/lodash-es/debounce.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import isObject from './isObject.js';
                                                                                                ^^^^^^^^

SyntaxError: Unexpected identifier

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
  at Object.<anonymous> (node_modules/recyclerlistview/src/core/RecyclerListView.tsx:21:1)

package.json

"dependencies":{

"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-native": "0.56.0",
"react-native-navigation": "^1.1.473",
"react-native-video": "^3.0.0",
"react-native-video-controls": "^2.2.3",
"recyclerlistview": "^1.3.4"

},
"devDependencies": {

"@babel/core": "^7.0.0-beta.53",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "23.4.0",
"babel-preset-react-native": "5.0.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "^3.3.4",
"jest": "23.4.0",
"react-native-mock": "^0.3.1",
"react-test-renderer": "16.4.1"

},
"jest": {

"preset": "react-native",
"testMatch": [
  "**/?(*.)test.js?(x)"
],
"snapshotSerializers": [
  "enzyme-to-json/serializer"
],
"setupFiles": [
  "<rootDir>/__tests__/setup.js"
],
"transformIgnorePatterns": [
  "node_modules/(?!react-native|recyclerlistview)",
  "node_modules/(?!react-native|lodash-es)"
]

}

Also getting this same error. Can you clarify this statement?

You can just pass it through the transpile process as well to fix this.

i'm getting the same error, any news on how to fix that?

Our solution to this issue:

We added recyclerlistview to the transformIgnorePatterns property of jest.config.js. This appears to be properly transpiling things now.

jest.config.js:

module.exports = {
...
  transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!react-native|react-navigation|lodash-es|recyclerlistview)',
  ],
...
}

Thanks @Meandmybadself for the fix here. That should ideally help with the issue at hand.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

h-asadollahi picture h-asadollahi  路  8Comments

teryi picture teryi  路  5Comments

sm2017 picture sm2017  路  5Comments

ajinkyadesai11-git picture ajinkyadesai11-git  路  4Comments

LukaszK88 picture LukaszK88  路  6Comments