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

Docker image not working with Yarn PnP - cannot find module #7419

Closed
aboe026 opened this issue Dec 14, 2022 · 3 comments
Closed

Docker image not working with Yarn PnP - cannot find module #7419

aboe026 opened this issue Dec 14, 2022 · 3 comments
Labels
AREA: docker TYPE: enhancement The accepted proposal for future implementation.

Comments

@aboe026
Copy link

aboe026 commented Dec 14, 2022

What is your Scenario?

I would like to run my repo set up with Yarn PnP through the testcafe docker image

What is the Current behavior?

When I attempt to run docker run --rm -v D:\path\to\testcafe-docker-yarn-pnp:/app -w /app -it testcafe/testcafe:2.1.0 chromium build/tests --config-file=.testcaferc.json I get the following error:

ERROR Cannot prepare tests due to the following error:

    Error: Cannot find module 'node-fetch'
    Require stack:
    - /app/build/tests/lifecycle.test.js
    - /usr/lib/node_modules/testcafe/lib/compiler/test-file/formats/es-next/compiler.js
    - /usr/lib/node_modules/testcafe/lib/compiler/compilers.js
    - /usr/lib/node_modules/testcafe/lib/compiler/index.js
    - /usr/lib/node_modules/testcafe/lib/runner/bootstrapper.js
    - /usr/lib/node_modules/testcafe/lib/runner/index.js
    - /usr/lib/node_modules/testcafe/lib/testcafe.js
    - /usr/lib/node_modules/testcafe/lib/index.js
    - /usr/lib/node_modules/testcafe/lib/cli/cli.js
    - /usr/lib/node_modules/testcafe/lib/cli/index.js
        at Object.<anonymous> (/app/tests/lifecycle.test.ts:2:1)

    Type "testcafe -h" for help.

What is the Expected behavior?

The tests should run without any errors around dependencies

What is your public website URL? (or attach your complete example)

https://github.com/aboe026/testcafe-docker-yarn-pnp

What is your TestCafe test code?

import { Selector } from 'testcafe'
import fetch from 'node-fetch'

fixture('Lifecycle').page('https://google.com')

test('Search bar exists', async (t) => {
  const result = await fetch('https://swapi.dev/api/people/1')
  const text = await result.text()
  let json
  try {
    json = JSON.parse(text)
  } catch (err) {
    throw Error(`Invalid JSON response '${text}': '${err}'`)
  }
  await t.expect(json.name).eql('Luke Skywalker')
  await t.expect(Selector('input[title="Search"]').exists).ok()
})

Your complete configuration file

{
  "browsers": ["edge"],
  "screenshots": {
    "path": "screenshots",
    "takeOnFails": true
  },
  "src": "build/tests"
}

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

Please see https://github.com/aboe026/testcafe-docker-yarn-pnp#steps-to-reproduce

TestCafe version

2.1.0

Node.js version

v16.13.2

Command-line arguments

docker run --rm -v D:\path\to\testcafe-docker-yarn-pnp:/app -w /app -it testcafe/testcafe:2.1.0 chromium build/tests --config-file=.testcaferc.json

Browser name(s) and version(s)

chromium

Platform(s) and version(s)

Windows 11

Other

No response

@aboe026 aboe026 added the TYPE: bug The described behavior is considered as wrong (bug). label Dec 14, 2022
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Dec 14, 2022
@aboe026
Copy link
Author

aboe026 commented Dec 14, 2022

I think I found a workaround: https://github.com/aboe026/testcafe-docker-yarn-pnp#workaround

Needed to alter the docker image like so:

FROM testcafe/testcafe

USER root

RUN npm install -g yarn && \
    sed --in-place --regexp-extended "s/^node /yarn node /" /opt/testcafe/docker/testcafe-docker.sh

USER user

@AndreyBelym AndreyBelym added TYPE: enhancement The accepted proposal for future implementation. and removed TYPE: bug The described behavior is considered as wrong (bug). labels Dec 16, 2022
@miherlosev
Copy link
Collaborator

miherlosev commented Dec 22, 2022

Hi @aboe026

I think I found a workaround: https://github.com/aboe026/testcafe-docker-yarn-pnp#workaround

I am happy to hear that.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Dec 22, 2022
@miherlosev
Copy link
Collaborator

Duplicate of #7710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AREA: docker TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

3 participants