cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.02k stars 1.09k forks source link

Cannot find module './cucumber.js' code: MODULE_NOT_FOUND #2313

Closed devexpert7 closed 11 months ago

devexpert7 commented 11 months ago

šŸ‘“ What did you see?

cucumber ts-node node-modules/@cucumber/cucumber/bin/cucumber.js -p default features --name say-hello node:internal/modules/cjs/loader:1080 throw err; ^

Error: Cannot find module './cucumber.js' Require stack:

āœ… What did you expect to see?

Able to run cucumber scenario

šŸ“¦ Which tool/library version are you using?

Cucumberjs ^9.3.0 Typescript 5.1.6 Node 18

šŸ”¬ How could we reproduce it?

Steps to reproduce the behavior:

  1. Install Cucumber

  2. "@cucumber/cucumber": "^9.3.0", "chromedriver": "^115.0.1", "cucumber": "^6.0.7", "source-map-loader": "^4.0.1", "ts-node": "^10.9.1"

  3. Create a file called support.ts import assert from "assert" import { When, Then } from "cucumber" import Greeter from "../src/index"

When('the greeter says hello', function () { // Write code here that turns the phrase above into concrete actions return 'pending'; });

When("the greeter says hello1", function() { console.log("hurrayy"); this.whatIHerad = new Greeter().sayHello() })

Then("I should have heard {string}", function(expectedResponse) { assert.equal(this.whatIHerad, expectedResponse) })

and also create file greeting.feature Feature: Greeting

Scenario: say-hello When the greeter says hello Then I should have heard "hello"

  1. Run command 'npm run cucumber -- features say-hello
  2. See error '....' Error: Cannot find module './cucumber.js' Require stack:
    • /Users/node-modules/@cucumber/cucumber/bin/imaginaryUncacheableRequireResolveScript

šŸ“š Any additional context?

0

I have node 18.17.1 and npm 9.6.7 on my machine.

I am trying to run the cucumber scenario and getting a module not found error when I try to execute the cucumber scenario. I tried npm install multiple times but was not able to get rid of this error.

terminal % npm run cucumber -- features --name say-hello

Below is package.json

{ "type": "module", "files": [ "src", "cucumber.js" ], "scripts": { "cucumber": "ts-node node-modules/@cucumber/cucumber/bin/cucumber.js -p default" }, "dependencies": { "@cucumber/cucumber": "^9.0.1", "chromedriver": "^115.0.1", "cucumber": "^6.0.7", "ts-node": "^10.9.1", "typescript": "5.1.6" } } I tried different cucumber versions and npm install multiple times and also tried clean cache. I was expecting this error is not thrown and execution is successful but getting this error every time.


This text was originally generated from a template, then edited by hand. You can modify the template here.

devexpert7 commented 11 months ago

This was resolved using --loader ts-node/esm loader.