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.

"npm start" app works, "npm test" fails test with syntax error on export

See original GitHub issue

Is this a bug report?

yes

Did you try recovering your dependencies?

yes (Write your answer here.)

Which terms did you search for in User Guide?

(Write your answer here if relevant.)

Environment

PS …/gold-line-sac > npx create-react-app --info

Environment: OS: Windows 10 Node: 10.9.0 Yarn: 1.9.4 npm: 6.2.0 Watchman: Not Found Xcode: N/A Android Studio: Version 3.1.0.0 AI-173.4819257

Packages: (wanted => installed) react: ^16.4.2 => 16.4.2 react-dom: ^16.4.2 => 16.4.2 react-scripts: 1.1.5 => 1.1.5

PS …/gold-line-sac > (paste the output of the command here)

Steps to Reproduce

(Write your steps here:)

  1. cd to my-app

  2. npm start

  3. notice app works importing testobj successfully. Browser displays: 'testob: '+JSON.stringify(testob) testob: {“k1”:“v1”,“k2”:“v2”,“k3”:“v3”}

  4. npm test FAIL src\App.test.js ● Test suite failed to run

    PATH\gold-line-sac\src\m\gold-line-data.mjs:48 export const testobj = {“k1”:“v1”, “k2”:“v2”, “k3”:“v3”}; ^^^^^^

    SyntaxError: Unexpected token export

    at new Script (vm.js:73:7) at Object.<anonymous> (src/App.js:9:194)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.83s Ran all test suites.

Expected Behavior

I thought the test would pass

Actual Behavior

the test failed saying it encountered a syntax error:

  1. npm test FAIL src\App.test.js ● Test suite failed to run

    PATH\gold-line-sac\src\m\gold-line-data.mjs:48 export const testobj = {“k1”:“v1”, “k2”:“v2”, “k3”:“v3”}; ^^^^^^

    SyntaxError: Unexpected token export

    at new Script (vm.js:73:7) at Object.<anonymous> (src/App.js:9:194)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.83s Ran all test suites.

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.) Here is the Reproducible Demo Link https://github.com/JoeCodeswell/react-test-prob-demo

Instructions to reproduce:

  1. install the demo code
  2. run npm start
  3. NOTICE app works importing testobj, etc successfully. Browser displays: 'testob: '+JSON.stringify(testob) testob: {“k1”:“v1”,“k2”:“v2”,“k3”:“v3”}
  4. run npm test
  5. NOTICE test FAILS saying “SyntaxError: Unexpected token export…” When this WORKED in the npm start command:
FAIL  src\App.test.js
  ● Test suite failed to run

    PATH\gold-line-sac\src\m\gold-line-data.mjs:48
    export const testobj =  {"k1":"v1", "k2":"v2", "k3":"v3"};
    ^^^^^^

    SyntaxError: Unexpected token export

      at new Script (vm.js:73:7)
      at Object.<anonymous> (src/App.js:9:194)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.83s
Ran all test suites.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
JoeCodeswellcommented, Sep 8, 2018

Hi, Ricardo.

I am not “using” ReactDOM . This is the way create-react-app comes out of the box.

I am reporting a create-react-app bug.

I expect, if i do nothing to cause a problem, that running npm test on an almost out of the box create-react-app, will not display a failure message.

I know i have not caused a problem because when i run npm start, the app works. It imports testobj successfully. the browser displays: 'testob: '+JSON.stringify(testob) testob: {“k1”:“v1”,“k2”:“v2”,“k3”:“v3”}

Thanks for your comment, Ricardo. Love and peace, Joe

0reactions
stale[bot]commented, Nov 17, 2018

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest gives an error: "SyntaxError: Unexpected token export"
This looks like an issue with Jest transforming a node module before running it's tests. Here is my .babelrc: { "presets": ["react", "es2015",...
Read more >
jest unexpected token export node_modules - You.com | The Search ...
Try npm start and note that the "app" works. Try npm test and note that tests fail with SyntaxError: Unexpected token export.
Read more >
npm-run-script
Description. This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts.
Read more >
How I Fixed The Unexpected Token Error In Jest
Solution #2 - A React Project (with create-react-app )​​ json file in this project. Everything I need is right here in package. json...
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping ......
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