Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run tests on local machine using @wdio/selenium-standalone-service because of ERR_REQUIRE_ESM #3574

Closed
esther-86 opened this issue Jan 30, 2023 · 6 comments · Fixed by #4123
Labels

Comments

@esther-86
Copy link

esther-86 commented Jan 30, 2023

What are you trying to achieve?

I would like to run tests locally using @wdio/selenium-standalone-service

What do you get instead?

Could not load plugin wdio from module './plugin/wdio':

Provide console output if related. Use --verbose mode for more details.

Could not load plugin wdio from module './plugin/wdio':
Couldn't initialise "@wdio/selenium-standalone-service".
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/@wdio/selenium-standalone-service/build/index.js
require() of ES modules is not supported.
require() of /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/@wdio/selenium-standalone-service/build/index.js from /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/plugin/wdio.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/@wdio/selenium-standalone-service/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1015:13)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at safeRequire (/Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/plugin/wdio.js:246:12)
    at module.exports (/Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/plugin/wdio.js:104:21)
    at createPlugins (/Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/container.js:291:44)
    at Function.create (/Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/container.js:47:25)
    at Codecept.init (/Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/codecept.js:56:15)
Error: Couldn't initialise "@wdio/selenium-standalone-service".
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/@wdio/selenium-standalone-service/build/index.js
require() of ES modules is not supported.
require() of /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/@wdio/selenium-standalone-service/build/index.js from /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/codeceptjs/lib/plugin/wdio.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users//Desktop/Repositories/PoCs/codecept_poc/node_modules/@wdio/selenium-standalone-service/package.json.

Provide test source code if related

Feature('login');

Scenario('test something', async ({ I }) => {
    await I.amOnPage('/')
});

Details

  • CodeceptJS version: 3.3.7
  • NodeJS Version: Had 12.22.6, then installed and set it to use 18.13.0
  • Operating System: macOS Monterey MacBook Pro (16-inch, 2019)
  • puppeteer || webdriverio || testcafe version (if related): webdriverio
  • Configuration file:
import { setHeadlessWhen, setCommonPlugins } from '@codeceptjs/configure';
// turn on headless mode when running with HEADLESS=true environment variable
// export HEADLESS=true && npx codeceptjs run
setHeadlessWhen(process.env.HEADLESS);

// enable all common plugins https://github.com/codeceptjs/configure#setcommonplugins
setCommonPlugins();

export const config: CodeceptJS.MainConfig = {
  tests: './*_test.ts',
  output: './output',
  helpers: {
    WebDriver: {
      url: 'http://www.google.com',
      browser: 'chrome'
    }
  },
  include: {
    I: './steps_file'
  },
  name: 'codecept-js-huong',
  fullPromiseBased: true,
  plugins: {
        pauseOnFail: {},
        retryFailedStep: {
            enabled: true
        },
        tryTo: {
            enabled: true
        },
        screenshotOnFail: {
            enabled: true
        },
        wdio: {
            enabled: true,
            services: ['selenium-standalone']
        }
    }
}
@esther-86
Copy link
Author

ESM version: https://www.youtube.com/watch?v=sLW4YEl5IIA
wdio/selenium-standalone-service uses ESM: https://openbase.com/js/@wdio/selenium-standalone-service (version 8)

Solution:
Use
"@wdio/selenium-standalone-service": "^7.30.0",
"webdriverio": "^7.30.0"

@esther-86 esther-86 reopened this Jan 31, 2023
@esther-86
Copy link
Author

esther-86 commented Jan 31, 2023

I'm re-opening this because the above solution is actually just a workaround. I want to be able to use the latest wdio/selenium-standalone-service with webdriverio helper. I already tried to create a CodeceptJS project with TypeScript and set "type":"module" in package.json but I'm still getting this error (when I did something similar for webdriverio project without Codecept it was able to run)

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users//Desktop/Repositories/PoCs/codecept-ts-huong/codecept.conf.ts
require() of ES modules is not supported.
require() of /Users//Desktop/Repositories/PoCs/codecept-ts-huong/codecept.conf.ts from /Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/codeceptjs/lib/config.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from /Users//Desktop/Repositories/PoCs/codecept-ts-huong/package.json.

    at createErrRequireEsm (/Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/ts-node/dist-raw/node-internal-errors.js:46:15)
    at assertScriptCanLoadAsCJSImpl (/Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/ts-node/dist-raw/node-internal-modules-cjs-loader.js:584:11)
    at Object.require.extensions.<computed> [as .ts] (/Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/ts-node/src/index.ts:1610:5)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Function.Module._load (node:internal/modules/cjs/loader:922:12)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at loadConfigFile (/Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/codeceptjs/lib/config.js:156:26)
    at Function.load (/Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/codeceptjs/lib/config.js:95:16)
    at module.exports.getConfig (/Users//Desktop/Repositories/PoCs/codecept-ts-huong/node_modules/codeceptjs/lib/command/utils.js:15:33)

I also took a look at these resources, and others, but am not understanding the problem, maybe because I am new to Javascript

https://stackoverflow.com/questions/69081410/error-err-require-esm-require-of-es-module-not-supported
https://stackoverflow.com/questions/61401475/why-is-type-module-in-package-json-file
https://codecept.discourse.group/t/selenium-standalone-service-plugin-can-not-working/236/2
standard-things/esm#855

@kobenguyent
Copy link
Collaborator

ESM version: https://www.youtube.com/watch?v=sLW4YEl5IIA wdio/selenium-standalone-service uses ESM: https://openbase.com/js/@wdio/selenium-standalone-service (version 8)

Solution: Use "@wdio/selenium-standalone-service": "^7.30.0", "webdriverio": "^7.30.0"

"@wdio/selenium-standalone-service": "^7.30.0",
"webdriverio": "^8.3.5"

this combination also works

@github-actions
Copy link

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Aug 22, 2023
@vcua-mobify
Copy link

Could this be reviewed? As of it's latest release @wdio/selenium-standalone-service is no longer being maintained. This is because WebdriverIO has moved to eliminate driver services as of WebdriverIO 8.14.

Instructions for setting up Webdriver should probably be updated to no longer use @wdio/selenium-standalone-service

@kobenguyent kobenguyent mentioned this issue Jan 10, 2024
8 tasks
@kobenguyent
Copy link
Collaborator

thank you @vcua-mobify once this #4123 is merged, this won't be an issue anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants