nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.63k stars 2.36k forks source link

Cannot Generate Cypress Project on 13.10 #9756

Closed vectorhacker closed 2 years ago

vectorhacker commented 2 years ago

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 commented 2 years ago

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
vectorhacker commented 2 years ago

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 commented 2 years ago

@vectorhacker can you provide the full stack trace?

vectorhacker commented 2 years ago

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

barbados-clemens commented 2 years ago

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

yarn nx g @nrwl/cypress:cypress-project --name=<e2e-name> --project=<project> --verbose
barbados-clemens commented 2 years ago

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

vectorhacker commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

"targets": {
    "serve": {
      "executor":"@nrwl/workspace:run-script",
      "options": {
        "script": "serve"
      }
    }
  }
barbados-clemens commented 2 years ago

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 commented 2 years ago

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

github-actions[bot] commented 1 year ago

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.