Answer the question
In order to leave comments, you need to log in
Why doesn't Jest understand the syntax?. in the imported file?
1. Created an npm package with a useful feature. Tested with jest, published on npm
2. Checked on codesandbox, importing the package and running the function - everything works fine
3. Now I create another package, into which I import the first one and when I run the tests through jest I get an error
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, eg it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Details:
C:\OSPanel\domains\localhost\js projects\sql-for-js-simple\node_modules\split-smartly\index.js:452 (searchSettings.mentions?.[fragment] && ACTION_ADD_FRAGMENT) ^
SyntaxError: Unexpected token .
searchSettings.mentions?.[fragment]
Answer the question
In order to leave comments, you need to log in
Apparently your other project is not configured to understand the syntax "?."
The message from jest is quite informative
"This usually means that you are trying to import a file which Jest cannot parse, eg it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules.""
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question