question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: Unexpected token import

See original GitHub issue

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.<anonymous>":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.<anonymous> (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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
Meandmybadselfcommented, Apr 29, 2019

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)',
  ],
...
}
1reaction
ZeroSingularitycommented, Jul 31, 2018

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)"
]

}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js - SyntaxError: Unexpected token import - Stack Overflow
Use transpiler like Babel to use import in Nodejs as it is not natively supported in nodejs.There is best alternative of import is...
Read more >
SyntaxError: Unexpected token import in Node.js | bobbyhadz
The "SyntaxError: Unexpected token import" occurs when we use the ES6 import syntax in a version of Node that doesn't support it. To...
Read more >
Unexpected token import Node.js - Reactgo
In this tutorial, we are going to learn about how to resolve the unexpected token import error in Node.js.
Read more >
Nodejs Uncaught SyntaxError: Unexpected token import
An unexpected token import occurs when an error message appears in the console while running a web application.
Read more >
Error Unexpected token import in nodejs | Edureka Community
SyntaxError : Unexpected token import at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Object.Module.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found