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

Error: Can't walk dependency graph: Cannot find module #1229

Closed
3 tasks done
voloKh28 opened this issue Aug 28, 2024 · 1 comment
Closed
3 tasks done

Error: Can't walk dependency graph: Cannot find module #1229

voloKh28 opened this issue Aug 28, 2024 · 1 comment

Comments

@voloKh28
Copy link

voloKh28 commented Aug 28, 2024

Current behavior

Issue while running the e2e
Error: Can't walk dependency graph: Cannot find module '@dbh/e2e' from '/Users/.../src/support/index.ts'

Desired behavior

e2e are running fine with custom supportFile

Test code to reproduce

I have cypress.config.ts with the following settings:

import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
import { preprocessor } from '@badeball/cypress-cucumber-preprocessor/browserify';
import { nxE2EPreset } from '@nrwl/cypress/plugins/cypress-preset';
import { defineConfig } from 'cypress';

const defaultConfig = nxE2EPreset(__dirname);

async function setupNodeEvents(
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions,
): Promise<Cypress.PluginConfigOptions> {
  // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  await addCucumberPreprocessorPlugin(on, config);

  on(
    'file:preprocessor',
    preprocessor(config, {
      typescript: require.resolve('typescript'),
    }),
  );

  // Make sure to return the config object as it might have been modified by the plugin.
  return config;
}

export default defineConfig({
  fileServerFolder: '.',
  downloadsFolder: './src/downloads',
  fixturesFolder: './src/fixtures',
  modifyObstructiveCode: false,
  video: false,
  chromeWebSecurity: false,
  e2e: {
    ...defaultConfig,
    // It is not working with cucumber configurations, I don't know why, it just doesn't see the module path @dbh/e2e
    supportFile: './src/support/index.ts',

    // below is a configuration for the cucumber BDD approach, uncomment it to check how the test is running
    setupNodeEvents: setupNodeEvents,
    specPattern: '**/*.feature',
  },
  env: {
    // Place values here which should be set as environment values. Usage: Cypress.env('SOME_ENV_VARIABLE')
  },
});

Because of my custom supportFile I have this issue, whenever I comment supportFile: './src/support/index.ts', it works fine. In my supportFile I have exports of different helper functions, so I need to have this support file to be configured, the file looks like this:

import '@dbh/e2e';

In my tsconfig.json I have all configurations with path aliases included:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "sourceMap": false,
    "outDir": "../../dist/out-tsc",
    "allowJs": true,
    "types": ["cypress", "node"],
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "esModuleInterop": true,
    "module": "nodenext",
    "paths": {
      "@dbh/e2e": [
        "libs/e2e/src/index.ts"
      ],
    }
  },
  "include": ["src/**/*.ts", "src/**/*.js", "cypress.config.ts"]
}

Not sure why this error occurs only when I have my custom setting of supportFile, I assume something could be wrong because of Nx, but I can not think of any specific reason.

Appreciate any help here, thanks in advance.

Versions

  • Cypress version: "^12.2.0",
  • nrwl Cypress version: "15.9.7",
  • Preprocessor version: "^20.1.1",
  • Node version: v20.17.0

Checklist

@badeball
Copy link
Owner

I don't think browserify will read your typescript.json config at all, ref. this. Thus I recommend that you use a different bundler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants