cypress-docker-images
cypress-docker-images copied to clipboard
Cant get typescript to work using cypress/included:6.2.1
Not sure why this is failing.. when I build this image using docker it passes fine, I even get it to spit out the tsc version, verifying that typescript support is installed on the image.
Error message im getting when attempting to run a spec file: "Error: You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have 'typescript' installed to enable TypeScript support."
My dockerfile:
# pull official Cypress image
FROM cypress/included:6.2.1
RUN mkdir /usr/src/app
RUN mkdir /usr/src/app/e2e
RUN mkdir /usr/src/app/e2e/cypress
WORKDIR /usr/src/app/e2e/cypress
RUN npm i typescript -g
RUN tsc --version
WORKDIR /usr/src/app/
COPY ./na/e2e/cypress/ /usr/src/app/e2e/cypress
COPY ./loadJWT /usr/src/app
COPY ./na/cypress.json /usr/src/app/cypress.json
I've tried to npm i a local package.json containing typescript to no avail. The application still complains about it not being installed. I will try to build my own image from scratch and see if I get a different result
I am seeing a similar issue with cypress/included:6.3.0 when attempting to run on a remote Jenkins. The docker compose file works fine locally and runs with no issues.
But on Jenkins I get the same error as above: Error: You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have 'typescript' installed to enable TypeScript support.
The docker-compose looks like this:
version: '3.8'
services:
app-test:
build:
context: ../../.
dockerfile: ./docker/test/Dockerfile
environment:
- NODE_ENV=production
logging:
driver: 'none'
cypress:
image: 'cypress/included:6.3.0'
depends_on:
- iq-test
environment:
- CYPRESS_baseUrl=http://app-test:3000
working_dir: /cypress
volumes:
- ../../:/cypress
And I run it like docker-compose -f ./docker/test/docker-compose.yml up --exit-code-from cypress
I had the same problem. It worked perfectly on my local machine. Turns out I just forgot to run yarn in my CI before I ran cypress run 🤦. The reason it worked locally was that it used node_modules in the local repository folder.
Yup! That resolved it for me as well. Forgot to update this.
Could you please explain, what exactly you had to change to make it work, @johachi and @mdemin914?
I'm stuck with the same problem and couldn't figure out what you mean by running yarn before cypress run. Do you do that the docker image?
@LeonGeorgi I think I just installed typescript in the Jenkins build step. We switched from Jenkins to Gitlab, so I am not sure if that was it, but this was the only reference I found in the Jenkinsfile that uses docker-compose from the original question.
stage('Run tests') {
steps {
sh '''
yarn add typescript
docker-compose -f ./docker/test/docker-compose.yml build --no-cache
docker-compose -f ./docker/test/docker-compose.yml up --exit-code-from cypress
'''
}
cypress run needs to have access to typescript in the project folder.
See this code:
export function hasTypeScriptInstalled (projectRoot: string) {
try {
require.resolve('typescript', { paths: [projectRoot] })
return true
} catch (e) {
return false
}
}
So you either need to npm install typescript in the folder you are running the project from or mount a folder that already has it installed (which is what caught me out too and is why it worked locally and not in CI).
I didn't want to npm install in the container running this so I did this:
docker run --entrypoint '/bin/bash' --network host --rm --volume $PWD:/e2e --workdir /e2e cypress/included:11.0.1 -c 'rm package* && npm install typescript && cypress run'
And it sorted it.
I just had a look in the latest cypress/included container and it does actually have typescript installed at /usr/local/lib/node_modules so ln -s /usr/local/lib/node_modules ./node_modules would also work depending on your use case.