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.

Error when running ios-basic-interactions.test.js

See original GitHub issue

The problem

I am trying to run the ios-basic-interactions.test.js but an error is thrown immediately after I try to run the test.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.16.0
  • Desktop OS/version used to run Appium: macOS 10.14.6
  • Node.js version (unless using Appium.app|exe): 13.6.0
  • Mobile platform/version under test: iOS 13
  • Real device or emulator/simulator: Simulator
  • Appium CLI or Appium.app|exe: CLI

Code To Reproduce Issue [ Good To Have ]

$ appium & node ios-basic-interactions.test.js 
[1] 32187
(node:32188) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Users/me/app/ios-basic-interactions.test.js:1
import wd from 'wd';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1060:16)
    at Module._compile (internal/modules/cjs/loader.js:1108:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
    at Module.load (internal/modules/cjs/loader.js:993:32)
    at Function.Module._load (internal/modules/cjs/loader.js:892:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
me:~/app $ [Appium] Welcome to Appium v1.16.0
[Appium] Appium REST http interface listener started on 0.0.0.0:4723

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
euoiacommented, May 20, 2020

Responding to my own comment, I may have been running the command from the wrong directory.

After running npm test in the sample-code directory, and then changing to the javascript-wd and re-running the command: javascript-wd|master ⇒ $(npm bin)/mocha test/basic/ios-basic-interactions.test.js

I no longer got the previous error. I got another error, but it’s probably unrelated.

0reactions
biajicommented, Aug 3, 2021

Ok, I’m facing the same here, maybe there still something wrong or misconfigration:

 pwd
..../appium-master/sample-code/javascript-wd 

npm -v
6.14.6

node -v
v12.18.3


npm run test

> javascript-wd@1.0.0 test /Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd
> mocha test/**/*.test.js


/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/test/basic/android-basic-interactions.test.js:1
import wd from 'wd';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1053:16)
    at Module._compile (internal/modules/cjs/loader.js:1101:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.exports.requireOrImport (/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/mocha/lib/esm-utils.js:42:12)
    at Object.exports.loadFilesAsync (/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/mocha/lib/esm-utils.js:55:34)
    at Mocha.loadFilesAsync (/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/mocha/lib/mocha.js:473:19)
    at singleRun (/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/mocha/lib/cli/run-helpers.js:125:15)
    at exports.runMocha (/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/mocha/lib/cli/run-helpers.js:190:10)
    at Object.exports.handler (/Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/mocha/lib/cli/run.js:362:11)
    at /Users/biaji/workspace/zte/Tests/appium-master/sample-code/javascript-wd/node_modules/yargs/build/index.cjs:443:71
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! javascript-wd@1.0.0 test: `mocha test/**/*.test.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the javascript-wd@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/biaji/.npm/_logs/2021-08-03T08_51_16_241Z-debug.log

It’s wired the complain of “SyntaxError: Cannot use import statement outside a module”.

Maybe it releated to babel ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing With Problems With Running Tests | Detox
This page is about issues related to executing your Detox tests, typically triggered when running detox test (and not detox build, for example)....
Read more >
Unit test not working on Xcode 14 RC
In my case setting Host Application in the test target settings > General > Testing from "None" to the main app solved this...
Read more >
NotAllowedError: play() failed because the user didn't ...
The main problem problem with this was that it was really difficult to find out in which component or service this error was...
Read more >
Handling common JavaScript problems - MDN Web Docs
Familiarity with the core HTML, CSS, and JavaScript languages; an idea of the high-level principles of cross browser testing. Objective: To be ...
Read more >
iOS Unit Testing and UI Testing Tutorial
Generally, tests should cover: Core functionality: Model classes and methods and their interactions with the controller; The most common UI ...
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