webdriverio: after 5.x upgrade test runner fails with "Error: You can't reassign a plugin after appling another plugin"

I’m trying to upgrade a webdriverio 4.x test suite to 5.x and when I launch the test suite using 5.x I get this error:

/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/@wdio/cli/node_modules/@wdio/config/build/utils.js:97
      throw new Error(`Couldn't initialise "${name}".\n${e.stack}`);
      ^

Error: Couldn't initialise "@wdio/local-runner".
Error: You can't reassign a plugin after appling another plugin
    at Object.apply (/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/loglevel-plugin-prefix/lib/loglevel-plugin-prefix.js:49:13)
    at Object.<anonymous> (/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/@wdio/local-runner/node_modules/@wdio/logger/build/node.js:98:31)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/@wdio/local-runner/node_modules/@wdio/logger/build/index.js:11:126)
    at safeRequire (/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/@wdio/cli/node_modules/@wdio/config/build/utils.js:97:13)
    at initialisePlugin (/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/@wdio/cli/node_modules/@wdio/config/build/utils.js:124:24)
    at new Launcher (/home/molsson/dv/webdriverio-5.x-reassign-plugin-bug/node_modules/@wdio/cli/build/launcher.js:42:49)

The bug can be reproduced by running “npm test” in the example repo below:

  1. git clone git@github.com:mo/wdio-v5-cant-reassign-plugin-bug.git
  2. npm test
  3. see error

What I found so far trying to debug this is that:

  • There is a function called “apply” at: ./node_modules/loglevel-plugin-prefix/lib/loglevel-plugin-prefix.js:49
  • It is being called twice but seems designed to be called only once.
  • I logged complete stack traces to both the first and the second time it gets called and I put those stacktraces into a diff viewer (see screenshot below).
  • It seems that the first call is coming from @wdio/cli and the second call is coming from @wdio/sync ?
  • One thing to note is that despite A) wdio.conf.js says “sync: true” and B) @wdio/sync is installed, I can still see the debug message “DEBUG wdio-config: wdio-sync not found, running tests asynchronous” flashing by even though this message gets cleared from the screen almost immediately. If I run “npm test 2>&1 | tee whatever.txt” and then inspect whatever.txt I can capture the error though.
  • Finally, while trying to search for similar github issues, I did find this one: https://github.com/webdriverio/webdriverio/issues/3057 … but that one was never really fixed.

image

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 14
  • Comments: 26 (11 by maintainers)

Most upvoted comments

I have this error too. Maybe for someone to will help. If you use old versions there is no error. like: image

Closing this. It is not reproducible for me. If you encounter this issue please clean your node-modules directory and package-lock.json and rerun npm install

@Ragner16 sorry to say it’s a regression in the latest version, so you are right!

to workaround, install the previous version: npm i --save-dev @wdio/cli@6.10.5

I ended up hitting this issue when enabling greenkeeper on a repo of mine. This bit from the upgrade blog post is the key:

Going forward the version number of all packages are now pinned to each other; meaning that you should always have the same versions for all “official” WebdriverIO packages that you use.

rm -rf node_modules package-lock.json && npm install worked for me. I ended up solving this problem for good by pinning the versions down to specific, more-or-less same versions of the various wdio projects. Here’s the diff:

diff --git a/package.json b/package.json
index 448b81d..533791b 100644
--- a/package.json
+++ b/package.json
@@ -35,10 +35,10 @@
     "uri-js": "^4.2.2"
   },
   "devDependencies": {
-    "@wdio/cli": "^5.4.17",
-    "@wdio/local-runner": "^5.4.17",
-    "@wdio/mocha-framework": "^5.4.14",
-    "@wdio/spec-reporter": "^5.4.15",
+    "@wdio/cli": "5.6.6",
+    "@wdio/local-runner": "5.6.6",
+    "@wdio/mocha-framework": "5.6.4",
+    "@wdio/spec-reporter": "5.6.4",
     "chromedriver": "^2.46.0",
     "eslint": "^5.9.0",
     "eslint-config-airbnb": "^17.1.0",
@@ -52,7 +52,7 @@
     "nock": "^10.0.1",
     "path": "^0.12.7",
     "remark": "^10.0.1",
-    "wdio-chromedriver-service": "^5.0.0",
-    "webdriverio": "^5.4.17"
+    "wdio-chromedriver-service": "5.0.1",
+    "webdriverio": "5.6.6"
   }
 }

I wonder if this can be made obvious somehow… The Getting Started guide on webdriver.io, for example, doesn’t mention anything about this, but the “use the same version for all wdio subprojects” bit of information, in my opinion, is necessary to know from the beginning to avoid falling into the issue described in here eventually.

I faced similar issue once, the problem was in package lock json. I can’t recommend delete it but in my case it helped. Can’t reproduce it clearly, I was switching versions here and there in a hacky way.

I see the exact same issue, and only by downgrading to 5.2.* can I work around it per @ViaMay’s post. Any idea when this will be investigated or resolved? @mo great writeup of the issue, thanks.

please see https://github.com/webdriverio/webdriverio/issues/6226

the fix should be released soon

I just followed the steps in “getting started guide” . May be this can help what’s there in Package.json “devDependencies”: { “@wdio/cli”: “^6.10.9”, “@wdio/mocha-framework”: “^6.10.6”, “@wdio/spec-reporter”: “^6.10.6”, “@wdio/sync”: “^6.10.7”, “chromedriver”: “^87.0.4”, “local”: “^0.3.3”, “wdio-chromedriver-service”: “^6.0.4” }

I did try changing version of cli and some others, surely its didint work , as there was some other error but it did try to initiate chrome browser.

Error still exist and its a shame that if you follow “getting started” from https://webdriver.io/docs/gettingstarted.html you will get this issue. I got some reference that this issue is due to new wdio version here https://phabricator.wikimedia.org/T231305 but it seems like it is solved but problem still exists . Wdio_error_local runner

Hey guys! I did exactly how it was mentioned above and the issue is gone for me. Thank you for the clarification.

brew install node

and then following upgrade instruction from https://webdriver.io/blog/2018/12/19/webdriverio-v5-released.html fixed the issue.

I am seeing the same issue. Just updated webdriverio to the latest version: 5.3.5, following https://webdriver.io/blog/2018/12/19/webdriverio-v5-released.html doc.

But I am getting an error when I am running tests.

     
Error: You can't reassign a plugin after appling another plugin

screen shot 2019-01-18 at 12 33 02 pm