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

Cannot Generate Cypress Project on 13.10 #9756

Closed
vectorhacker opened this issue Apr 8, 2022 · 13 comments · Fixed by #9795
Closed

Cannot Generate Cypress Project on 13.10 #9756

vectorhacker opened this issue Apr 8, 2022 · 13 comments · Fixed by #9795
Assignees
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@vectorhacker
Copy link

vectorhacker commented Apr 8, 2022

Current Behavior

Error generating cypress project. Getting error related to not being able to find the logger.

Expected Behavior

Be able to geenrate a cypress e2e project. This is the first time I've run this command.

Steps to Reproduce

Install @nrwl/cypress

yarn add --dev @nrwl/cypress
yarn nx generate @nrwl/cypress:cypress-project <project>-e2e --project=<project>

package.json:

{
  "name": "<name>",
  "version": "0.0.0",
  "private": true,
  "workspaces": [
    "apps/*",
    "packages/*",
    "tools/*"
  ],
  "devDependencies": {
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "@codebrew/nx-aws-cdk": "^1.0.3",
    "@craco/craco": "7.0.0-alpha.3",
    "@nrwl/cli": "^13.10.0",
    "@nrwl/cypress": "^13.10.0",
    "@nrwl/eslint-plugin-nx": "13.9.7",
    "@nrwl/jest": "13.9.7",
    "@nrwl/linter": "13.9.7",
    "@nrwl/react": "^13.9.7",
    "@nrwl/web": "13.9.7",
    "@nrwl/workspace": "13.10.0",
    "@testing-library/dom": "^8.13.0",
    "@testing-library/jest-dom": "^5.16.4",
    "@testing-library/react": "12.1.4",
    "@testing-library/react-hooks": "7.0.2",
    "@testing-library/user-event": "^13.5.0",
    "@tsconfig/node14": "^1.0.1",
    "@types/chance": "^1.1.3",
    "@types/graphql": "^14.5.0",
    "@types/jest": "27.0.2",
    "@types/node": "^17.0.23",
    "@types/react": "17.0.40",
    "@types/react-dom": "17.0.13",
    "@typescript-eslint/eslint-plugin": "~5.10.0",
    "@typescript-eslint/parser": "~5.10.0",
    "autoprefixer": "^10.4.4",
    "aws-sdk": "^2.1095.0",
    "babel-jest": "27.2.3",
    "babel-loader": "^8.2.4",
    "babel-webpack-plugin": "^0.1.2",
    "chalk": "^5.0.0",
    "chance": "^1.1.8",
    "craco-babel-loader": "^1.0.3",
    "cypress": "^9.1.0",
    "dotenv": "^16.0.0",
    "eslint": "^8.12.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-config-react-app": "^7.0.0",
    "eslint-plugin-": "nrwl/nx",
    "eslint-plugin-cdk": "^1.3.0",
    "eslint-plugin-cypress": "^2.10.3",
    "eslint-plugin-import": "2.25.4",
    "eslint-plugin-jsx-a11y": "6.5.1",
    "eslint-plugin-react": "7.29.3",
    "eslint-plugin-react-hooks": "4.3.0",
    "install-peerdeps": "^3.0.3",
    "jest": "27.2.3",
    "jest-console": "^0.1.0",
    "jest-junit": "^13.0.0",
    "jest-watch-typeahead": "^1.0.0",
    "mocha": "5.2.0",
    "mochawesome-report-generator": "^6.2.0",
    "nx": "^13.10.0",
    "postcss": "^8.4.12",
    "prettier": "^2.5.1",
    "react-scripts": "5",
    "react-test-renderer": "17.0.2",
    "ts-jest": "27.0.5",
    "typescript": "^4.6.3",
    "web-vitals": "^2.1.4",
    "webpack": "^5.72.0"
  },
  "engines": {
    "npm": ">=7.0.0",
    "node": ">=14.0.0"
  },
  "packageManager": "npm@8.5.0"
}

Failure Logs

Cannot find module 'nx/src/shared/logger'
Require stack:
- /Users/victor/dev/workspace/coquimono/node_modules/@nrwl/cypress/node_modules/@nrwl/devkit/index.js
- /Users/victor/dev/workspace/coquimono/node_modules/@nrwl/cypress/src/generators/cypress-project/cypress-project.js
- /Users/victor/dev/workspace/coquimono/node_modules/nx/src/config/workspaces.js
- /Users/victor/dev/workspace/coquimono/node_modules/nx/src/command-line/generate.js
- /Users/victor/dev/workspace/coquimono/node_modules/nx/src/command-line/nx-commands.js
- /Users/victor/dev/workspace/coquimono/node_modules/nx/bin/init-local.js
- /Users/victor/dev/workspace/coquimono/node_modules/nx/bin/nx.js

Environment

yarn run v1.22.18
$ /Users/victor/dev/workspace/coquimono/node_modules/.bin/nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.14.2
   OS   : darwin arm64
   yarn : 1.22.18
   
   nx : 13.10.0
   @nrwl/angular : Not Found
   @nrwl/cypress : 13.10.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 13.10.0
   @nrwl/eslint-plugin-nx : 13.9.7
   @nrwl/express : Not Found
   @nrwl/jest : 13.9.7
   @nrwl/js : 13.10.0
   @nrwl/linter : 13.9.7
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 13.10.0
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 13.10.0
   @nrwl/web : 13.9.7
   @nrwl/workspace : 13.10.0
   typescript : 4.6.3
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:
   	 @codebrew/nx-aws-cdk: 1.0.3

Done in 0.64s.
@barbados-clemens
Copy link
Contributor

barbados-clemens commented Apr 11, 2022

it looks like some of your packages are out of sync

    "@nrwl/jest": "13.9.7",
    "@nrwl/linter": "13.9.7",
    "@nrwl/react": "^13.9.7",
    "@nrwl/web": "13.9.7",

vs 13.10.0

npx create-nx-workspace --preset=apps

npm i -D @nrwl/cypress @nrwl/react

npx nx g @nrwl/react:app r-fe --e2eTestRunner=none
✔ Which stylesheet format would you like to use? · css
✔ Would you like to add React Router to this application? (y/N) · true

UPDATE nx.json
CREATE jest.config.js
CREATE jest.preset.js
UPDATE package.json
UPDATE .vscode/extensions.json
CREATE babel.config.json
CREATE apps/r-fe/.babelrc
CREATE apps/r-fe/.browserslistrc
CREATE apps/r-fe/src/app/app.spec.tsx
CREATE apps/r-fe/src/app/nx-welcome.tsx
CREATE apps/r-fe/src/assets/.gitkeep
CREATE apps/r-fe/src/environments/environment.prod.ts
CREATE apps/r-fe/src/environments/environment.ts
CREATE apps/r-fe/src/favicon.ico
CREATE apps/r-fe/src/index.html
CREATE apps/r-fe/src/main.tsx
CREATE apps/r-fe/src/polyfills.ts
CREATE apps/r-fe/tsconfig.app.json
CREATE apps/r-fe/tsconfig.json
CREATE apps/r-fe/src/app/app.module.css
CREATE apps/r-fe/src/app/app.tsx
CREATE apps/r-fe/src/styles.css
CREATE apps/r-fe/project.json
UPDATE workspace.json
CREATE .eslintrc.json
CREATE apps/r-fe/.eslintrc.json
CREATE apps/r-fe/jest.config.js
CREATE apps/r-fe/tsconfig.spec.json

npx nx g @nrwl/cypress:cypress-project --name=r-fe-e2e --project=r-fe
CREATE apps/r-fe-e2e/cypress.json
CREATE apps/r-fe-e2e/src/fixtures/example.json
CREATE apps/r-fe-e2e/src/integration/app.spec.ts
CREATE apps/r-fe-e2e/src/support/app.po.ts
CREATE apps/r-fe-e2e/src/support/commands.ts
CREATE apps/r-fe-e2e/src/support/index.ts
CREATE apps/r-fe-e2e/tsconfig.json
CREATE apps/r-fe-e2e/project.json
UPDATE workspace.json
CREATE apps/r-fe-e2e/.eslintrc.json
UPDATE package.json

@barbados-clemens barbados-clemens self-assigned this Apr 11, 2022
@barbados-clemens barbados-clemens added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Apr 11, 2022
@vectorhacker
Copy link
Author

vectorhacker commented Apr 11, 2022

I've updated my dependencies to the following:

    "@nrwl/cli": "^13.10.1",
    "@nrwl/cypress": "^13.10.1",
    "@nrwl/eslint-plugin-nx": "13.10.1",
    "@nrwl/jest": "13.10.1",
    "@nrwl/linter": "13.10.1",
    "@nrwl/react": "^13.10.1",
    "@nrwl/web": "13.10.1",
    "@nrwl/workspace": "13.10.1",
    "nx": "13.10.1"

I'm now getting this error message when running yarn nx g @nrwl/cypress:cypress-project --name=<e2e-name> --project=<project>:

Cannot read properties of undefined (reading 'serve')

@barbados-clemens
Copy link
Contributor

@vectorhacker can you provide the full stack trace?

@vectorhacker
Copy link
Author

@barbados-clemens how do I provide that? That's all the output I get.

@barbados-clemens
Copy link
Contributor

@vectorhacker you can use the --verbose flag with nx

yarn nx g @nrwl/cypress:cypress-project --name=<e2e-name> --project=<project> --verbose

@barbados-clemens
Copy link
Contributor

oops looks like you're running @nrwl/nrwl instead of @nrwl/cypress

@vectorhacker
Copy link
Author

vectorhacker commented Apr 11, 2022

@barbados-clemens yeah haha I just noticed. Sorry. Here's the real one.

yarn run v1.22.18
$ /Users/<user>/dev/workspace/<repo>/node_modules/.bin/nx g @nrwl/cypress:cypress-project --name=<project>-e2e --project=<project> --verbose
TypeError: Cannot read properties of undefined (reading 'serve')
    at addProject (/Users/<user>/dev/workspace/<repo>/node_modules/@nrwl/cypress/src/generators/cypress-project/cypress-project.js:52:49)
    at /Users/<user>/dev/workspace/<repo>/node_modules/@nrwl/cypress/src/generators/cypress-project/cypress-project.js:166:9
    at Generator.next (<anonymous>)
    at /Users/<user>/dev/workspace/<repo>/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/<user>/dev/workspace/<repo>/node_modules/tslib/tslib.js:113:16)
    at cypressProjectGenerator (/Users/<user>/dev/workspace/<repo>/node_modules/@nrwl/cypress/src/generators/cypress-project/cypress-project.js:163:20)
    at Object.<anonymous> (/Users/<user>/dev/workspace/<repo>/node_modules/nx/src/command-line/generate.js:128:36)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/<user>/dev/workspace/<repo>/node_modules/tslib/tslib.js:114:62)
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@barbados-clemens
Copy link
Contributor

does the --project you're passing to the cypress-project generator have a 'serve' target defined it the project.json?

the cypress-project generator adds the serve target to the e2e project devServerTarget executor options.

https://github.com/nrwl/nx/blob/master/packages/cypress/src/generators/cypress-project/cypress-project.ts#L85-L88

const devServerTarget =
      project.targets.serve && project.targets.serve.defaultConfiguration
        ? `${options.project}:serve:${project.targets.serve.defaultConfiguration}`
        : `${options.project}:serve`;

(we should probably null check this and display an error just in case)

@vectorhacker
Copy link
Author

The project doesn't have any targets cus I followed the migration guide for CRA apps to an nx workspace and it suggests to remove those targets. Do I need to add a serve target?

@vectorhacker
Copy link
Author

So, I just added a serve target that uses the run-script executor and it works now.

"targets": {
    "serve": {
      "executor":"@nrwl/workspace:run-script",
      "options": {
        "script": "serve"
      }
    }
  }

@barbados-clemens
Copy link
Contributor

typically the cypress project generator is called via other application generators which will always scaffold out a serve target. but in the case of a manual target then you'll need to either pass in the baseUrl or a project with a serve target.
in this case we aren't null checking the project to make sure it has a serve target leading to the error.

I'll update the cypress-project to null check the the project targets and print out an error message if one isn't found so you don't have this non discript error.

Thanks for finding the bug for us 😄

I'll leave this issue open to reference in the PR to make sure we give people better error with unexpected projects 👍

@vectorhacker
Copy link
Author

That's great! Glad I could be of help.

barbados-clemens added a commit that referenced this issue Apr 11, 2022
…does not have a serve target.

when trying to add cypress to a project that does not contain a serve target the project will error
out because of a null reference.
Now when trying to add to a project without a serve target a more
descriptive error is throw stating to add a serve target or use the --baseUrl flag
Note: a future
update should add the parameter to override what target to use if so desired.

ISSUES CLOSED: #9756
barbados-clemens added a commit that referenced this issue Apr 12, 2022
…t does not have targets defined.

when trying to add cypress to a project that does not contain targets the project will error
out because of a null reference.
Now when trying to add to a project without a serve target a more
descriptive message is logged stating to add a serve target or use the --baseUrl flag
Note: a future
update should add the parameter to override what target to use if so desired.

ISSUES CLOSED: #9756
barbados-clemens added a commit that referenced this issue Apr 12, 2022
…t does not have targets defined.

when trying to add cypress to a project that does not contain targets the project will error
out because of a null reference.
Now when trying to add to a project without a serve target a more
descriptive message is logged stating to add a serve target or use the --baseUrl flag
Note: a future
update should add the parameter to override what target to use if so desired.

ISSUES CLOSED: #9756
barbados-clemens added a commit that referenced this issue Apr 12, 2022
…ave targets defined. (#9795)

when trying to add cypress to a project that does not contain targets the project will error
out because of a null reference.
Now when trying to add to a project without a serve target a more
descriptive message is logged stating to add a serve target or use the --baseUrl flag
Note: a future
update should add the parameter to override what target to use if so desired.

ISSUES CLOSED: #9756
FrozenPandaz pushed a commit that referenced this issue Apr 13, 2022
…ave targets defined. (#9795)

when trying to add cypress to a project that does not contain targets the project will error
out because of a null reference.
Now when trying to add to a project without a serve target a more
descriptive message is logged stating to add a serve target or use the --baseUrl flag
Note: a future
update should add the parameter to override what target to use if so desired.

ISSUES CLOSED: #9756
@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
2 participants