Strange SyntaxError when running tests, probably transpiler bug
See original GitHub issueIs this a bug report?
Yes.
Can you also reproduce the problem with npm 4.x?
I’m using yarn. Tried npm 4 though. Same.
Which terms did you search for in User Guide?
Did a quick look-through. I searched google for SyntaxError: Unexpected identifier
, did not found the solution.
Environment
node -v
: v8.4.0npm -v
: 4.6.1 (was 5.x before)yarn --version
:0.27.5
npm ls react-scripts
:react-scripts@1.0.13
(also checked atreact-scripts@1.0.11
with yarn)
Switching yarn/npm seems to have no effect.
Then, specify:
- Operating system: Ubuntu xenial
- Browser and version (if relevant): -
Steps to Reproduce
The issue is really strange.
-
Create a new project,
cd
into it. -
yarn add flow-bin
(flow-bin@0.53.1
), thenyarn flow init
. -
Create two files:
src/dummy.js
// @flow
export const dummmmmmmmmmmmmmmmmmy = async (
response: Response
): Promise<Response> => {
if (!response.ok) {
const text = await response.text();
throw Error(text);
}
return response;
};
src/dummy.test.js
// @flow
import { dummmmmmmmmmmmmmmmmmy } from "./dummy";
it("should run", async () => {
await dummmmmmmmmmmmmmmmmmy(fetch("https://google.com"));
expect(true);
});
yarn test
Expected Behavior
Tests run successfully or at least fail with some sane error.
Actual Behavior
PASS src/App.test.js
FAIL src/dummy.test.js
● Test suite failed to run
.../issue/src/dummy.js:6
const text = await response.text();
^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
at Object.<anonymous> (src/dummy.test.js:2:14)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.517s, estimated 1s
Ran all test suites related to changed files.
Watch Usage
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
Done in 7.55s.
Seems to be related to the way code is formatted. 😮
Reproducible Demo
https://github.com/MOZGIII/js-bug-demo-1
Just cone it and yarn install
.
Run CI=true yarn test
. Pretend you’re CI to run all tests.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Jest not parsing es6: SyntaxError: Unexpected token import
When I run my tests, Jest complains it cannot read es6 code. Babel seems to not transform my test files. I have tried...
Read more >SyntaxError - JavaScript - MDN Web Docs
The SyntaxError object represents an error when trying to interpret syntactically invalid code. It is thrown when the JavaScript engine encounters tokens or ......
Read more >invalid string (possibly contains a unicode character) - Anvil Q&A
Hello, How do I solve this unicode error ? ... SyntaxError: invalid string (possibly contains a unicode character).
Read more >Frequently Asked Questions - Jasmine Documentation
This error means that something (probably a transpiler, but possibly the JavaScript runtime) has marked the exported properties of the module as read-only....
Read more >python to go transpiler - You.com | The search engine you control.
Notice that your error states SyntaxError: invalid syntax (guess you dropped x when rewriting). This means that you're trying to execute code that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m adding a regression test in https://github.com/facebookincubator/create-react-app/pull/3791 so this doesn’t break again.
This appears fixed in Babel 7 and doesn’t happen in our
next
branch. We’ll publish first 2.0 alphas soon.