Scarlet McLearn
Scarlet McLearn

Reputation: 71

Playwright Error: Cannot find module in Bitbucket Pipelines

Version used: 1.49.0

Steps to reproduce

I have the following files:

bitbucket-pipelines.yml

image: mcr.microsoft.com/playwright:v1.49.0-noble

pipelines:
  default:
    - step:
        name: Install dependencies
        caches:
          - node
        script:
          - npm ci
          - npx playwright install-deps
          - npx playwright install
    - step:
        name: Run Playwright tests
        script:
          - npx playwright test

package.json

{
  "name": "auxo-ael-fork-sakib",
  "version": "1.0.0",
  "description": "Test Automation framework using playwright and typescript",
  "main": "index.js",
  "scripts": {
    "lint": "eslint .",
    "format": "prettier --write .",
    "generate:report": "allure generate ./test-reports/allure-result --clean -o test-reports/allure-report",
    "open:report": "allure open ./test-reports/allure-report",
    "test:stg:chrome": "cross-env TEST_ENV=staging BROWSER=DesktopChrome npx playwright test --workers=4",
    "test:stg:firefox": "cross-env TEST_ENV=staging BROWSER=DesktopFirefox npx playwright test",
    "test:qa:chrome": "cross-env TEST_ENV=qa BROWSER=DesktopChrome npx playwright test",
    "test:qa:firefox": "cross-env TEST_ENV=qa BROWSER=DesktopFirefox npx playwright test",
    "test:stg:chrome:report": "cross-env TEST_ENV=staging BROWSER=DesktopChrome npx playwright test && npm run generate:report"
  },
  "repository": {
    "type": "git",
    "url": "git+https://[email protected]/auxo_solutions/auxo-ael-fork-sakib.git"
  },
  "author": "Md Sakibur Rahman (Espak)",
  "license": "ISC",
  "bugs": {
    "url": "https://[email protected]/auxo_solutions/auxo-ael-fork-sakib/issues"
  },
  "homepage": "https://[email protected]/auxo_solutions/auxo-ael-fork-sakib#readme",
  "devDependencies": {
    "@playwright/test": "^1.49.0",
    "@types/node": "^22.7.1",
    "allure-playwright": "^3.0.5",
    "cross-env": "^7.0.3",
    "eslint": "^9.11.1",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-playwright": "^1.6.2",
    "eslint-plugin-prettier": "^5.2.1",
    "prettier": "^3.3.3",
    "typescript": "^5.6.2"
  },
  "dependencies": {
    "dotenv": "^16.4.5"
  }
}

package.lock.json

When I try to run the pipeline, I get this error:

'/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/cli.js'
  ]
}
+ umask 000
+ GIT_LFS_SKIP_SMUDGE=1 retry 6 git clone --branch="main" --depth 50 https://x-token-auth:[email protected]/$BITBUCKET_REPO_FULL_NAME.git $BUILD_DIR
Cloning into '/opt/atlassian/pipelines/agent/build'...
+ git reset --hard c0b06957798ded6c5f3e75c110f78775aa7c80c3
HEAD is now at c0b0695 sd
+ git config user.name bitbucket-pipelines
+ git config user.email [email protected]
+ git config push.default current
+ git config http.${BITBUCKET_GIT_HTTP_ORIGIN}.proxy http://localhost:29418/
+ git remote set-url origin http://bitbucket.org/$BITBUCKET_REPO_FULL_NAME
+ git reflog expire --expire=all --all
+ echo ".bitbucket/pipelines/generated" >> .git/info/exclude
+ chmod 777 $BUILD_DIR
Default variables:
    BITBUCKET_BRANCH
    BITBUCKET_BUILD_NUMBER
    BITBUCKET_CLONE_DIR
    BITBUCKET_COMMIT
    BITBUCKET_GIT_HTTP_ORIGIN
    BITBUCKET_GIT_SSH_ORIGIN
    BITBUCKET_PIPELINE_UUID
    BITBUCKET_PROJECT_KEY
    BITBUCKET_PROJECT_UUID
    BITBUCKET_REPO_FULL_NAME
    BITBUCKET_REPO_IS_PRIVATE
    BITBUCKET_REPO_OWNER
    BITBUCKET_REPO_OWNER_UUID
    BITBUCKET_REPO_SLUG
    BITBUCKET_REPO_UUID
    BITBUCKET_SSH_KEY_FILE
    BITBUCKET_STEP_RUN_NUMBER
    BITBUCKET_STEP_TRIGGERER_UUID
    BITBUCKET_STEP_UUID
    BITBUCKET_WORKSPACE
    CI
    DOCKER_HOST
    PIPELINES_JWT_TOKEN
Images used:
    build : mcr.microsoft.com/playwright@sha256:0fc07c73230cb7c376a528d7ffc83c4bdcdcd3fc7efbe54a2eed72b1ec118377
Cloud runtime: 2
+ npx playwright test
npm warn exec The following package was not found and will be installed: [email protected]
Error: Cannot find module '@playwright/test'
Require stack:
- /opt/atlassian/pipelines/agent/build/playwright.config.ts
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/transform/transform.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/common/esmLoaderHost.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/processHost.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/loaderHost.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/loadUtils.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/reporters.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/runner.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/program.js
- /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/cli.js
    at Function.<anonymous> (node:internal/modules/cjs/loader:1249:15)
    at Function.resolveFilename [as _resolveFilename] (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/transform/transform.js:249:36)
    at Function._load (node:internal/modules/cjs/loader:1075:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/playwright.config.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module.f._compile (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/utilsBundleImpl.js:16:994)
    at node:internal/modules/cjs/loader:1689:10
    at Object.i.<computed>.ut._extensions.<computed> [as .ts] (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/utilsBundleImpl.js:16:1010)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at requireOrImport (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/transform/transform.js:230:18)
    at loadUserConfig (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/common/configLoader.js:94:83)
    at loadConfig (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/common/configLoader.js:105:28)
    at loadConfigFromFileRestartIfNeeded (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/common/configLoader.js:286:10)
    at runTests (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/program.js:199:18)
    at t.<anonymous> (/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/program.js:54:7) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/opt/atlassian/pipelines/agent/build/playwright.config.ts',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/transform/transform.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/common/esmLoaderHost.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/processHost.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/loaderHost.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/loadUtils.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/reporters.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/runner.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/program.js',
    '/root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/cli.js'
  ]
}
Searching for test report files in directories named [test-results, failsafe-reports, test-reports, TestResults, surefire-reports] down to a depth of 4
Finished scanning for test reports. Found 0 test report files.
Merged test suites, total number tests is 0, with 0 failures and 0 errors.

How to resolve this? I tried several different images, but it's not working.

Upvotes: 0

Views: 168

Answers (1)

N1ngu
N1ngu

Reputation: 3834

Each step runs in a brand new container. You can't install dependencies in a separate step because they will be unavailable in any following step.

image: mcr.microsoft.com/playwright:v1.49.0-noble

pipelines:
  default:
    - step:
        name: Run Playwright tests
        caches:
          - node
        script:
          - npm ci
          - npx playwright install-deps
          - npx playwright install
          - npx playwright test

Even if you are using a cache, do NOT try to abuse it to separate install instructions in a different step. That works sometimes but only accidentally, and you risk introducing a lot of chaos to your pipelines.

Upvotes: 1

Related Questions