Cannot use cucumber.js file with esm

See original GitHub issue

Describe the bug When using a cucumber.js file, cucumber fails if running with esm. Says it cannot use require to load the file

To Reproduce

  1. Use version 8.0.0-rc1
  2. Add a cucumber.js file to the root of your package.
  3. Set type: module in your package.json
  4. Run cucumber with steps written in esm format

Expected behavior cucumber.js should be able to use esm code and otherwise work as before.

Actual result

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /tmp/cucumber8/cucumber.js
require() of ES modules is not supported.
require() of /tmp/cucumber8/cucumber.js from /tmp/cucumber8/node_modules/@cucumber/cucumber/lib/cli/profile_loader.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 cucumber.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /tmp/cucumber8/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at ProfileLoader.loadFile (/tmp/cucumber8/node_modules/@cucumber/cucumber/lib/cli/profile_loader.js:28:29)
    at ProfileLoader.getDefinitions (/tmp/cucumber8/node_modules/@cucumber/cucumber/lib/cli/profile_loader.js:21:25)
    at ProfileLoader.getArgv (/tmp/cucumber8/node_modules/@cucumber/cucumber/lib/cli/profile_loader.js:35:40)
    at Object.getExpandedArgv (/tmp/cucumber8/node_modules/@cucumber/cucumber/lib/cli/helpers.js:37:65)

Besides that, thanks for pushing this release.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
aurelien-reevescommented, Oct 20, 2021

@davidjgoss you’ve been faster than me 😄

For reference, this is documented here, at the end: https://github.com/cucumber/cucumber-js/blob/main/docs/esm.md

0reactions
davidjgosscommented, Apr 18, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

esm: add support for loaders · Issue #1844 · cucumber ...
I got no such issue using ts-node/esm loader with a TypeScript project, see https://github.com/cucumber-examples/cucumber-js-examples/compare/ ...
Read more >
How do I use Cucumber with my ESM (ECMA Module Loader ...
I tried creating a .mjs version of the step file but I can't get that working either. I also tried cucumber-js --require-module features/support ......
Read more >
cucumber/cucumber-js - Gitter
Hi, I'm using cucumber-js with Typescript and am noticing that when I run my code via cucumber-js, the tsconfig.json file is not read....
Read more >
Frameworks - WebdriverIO
The WDIO runner currently supports Mocha, Jasmine, and Cucumber. ... your spec files (or step definitions), you can access the WebDriver instance using...
Read more >
Configuring Jest
The file will be discovered automatically, if it is named jest.config.js|ts|mjs|cjs|json . You can use --config flag to pass an explicit path to ......
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