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

Unable to use Cypress.require within cy.origin #25885

Closed
FlorianTopf opened this issue Feb 20, 2023 · 15 comments · Fixed by #25931
Closed

Unable to use Cypress.require within cy.origin #25885

FlorianTopf opened this issue Feb 20, 2023 · 15 comments · Fixed by #25931
Assignees
Labels
topic: cy.origin Problems or enhancements related to cy.origin command type: bug

Comments

@FlorianTopf
Copy link

FlorianTopf commented Feb 20, 2023

Current behavior

I am trying to use Cypress.require which was released with 12.6.0 to be able to import external dependencies within a cy.origin callback. I am using cypress within an angular project using typescript 4.7.4.

According to the documentation this should work with any typescript module:
https://docs.cypress.io/api/cypress-api/require

As soon as I start the test suite including a Cypress.require it immediately fails with:
Error: Cannot find module 'typescript'

Desired behavior

Absence of current behavior. Cypress.require should work as documented.

Test code to reproduce

// test.js
module.exports = {
    foo: 'bar',
};

// test.cy.ts
describe('Some test', (): void => {
   it('should work', (): void => {
      cy.origin('https://example.com', (): void => {
         const test = Cypress.require('./test.js');
         cy.log('test', test);
      });
   });
});

// cypress config
export default defineConfig({
    e2e: {
        baseUrl: 'http://0.0.0.0:4200',
        supportFile: 'cypress/support/e2e.ts',
        defaultCommandTimeout: 10000,
        video: false,
        experimentalOriginDependencies: true,
    },
});

Cypress Version

12.6.0

Node version

16.18.0

Operating System

macOS 12.6.1

Debug Logs

CypressError
cy.origin() failed to run the callback function due to the following error:



Processing the origin callback errored:



Error: Cannot find module 'typescript'

Require stack:

- /Users/floriantopf/Library/Caches/Cypress/12.6.0/Cypress.app/Contents/Resources/app/packages/server/lib/cross-origin/process-callback.ts

    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)

    at n._resolveFilename (node:electron/js2c/browser_init:249:1105)

    at PackherdModuleLoader._tryResolveFilename (evalmachine.<anonymous>:1:735006)

    at PackherdModuleLoader._resolvePaths (evalmachine.<anonymous>:1:731827)

    at PackherdModuleLoader.tryResolve (evalmachine.<anonymous>:1:727083)

    at resolve (evalmachine.<anonymous>:1:741891)

    at Function.resolve (evalmachine.<anonymous>:1:752340)

    at customRequire.resolve (<embedded>:5225:1350439)

    at _ (<embedded>:5166:22380)

    at <embedded>:5205:68107

    at a.handle_request (<embedded>:3012:1038)

    at i (<embedded>:3027:1285)

    at <embedded>:2627:2101

    at n (<embedded>:2608:1794)

    at p (<embedded>:2608:1813)

    at IncomingMessage.f (<embedded>:2608:2273)

    at IncomingMessage.emit (node:events:539:35)

    at endReadableNT (node:internal/streams/readable:1345:12)

    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)Learn more

Other

No response

@chrisbreiding
Copy link
Contributor

Sorry to see you're encountering an issue using Cypress.require(). I was able to reproduce the issue with the provided code. I'll route this to my team to investigate further.

@chrisbreiding chrisbreiding added routed-to-e2e type: bug topic: cy.origin Problems or enhancements related to cy.origin command labels Feb 20, 2023
@FlorianTopf
Copy link
Author

Thank you for the fast reply and for forwarding the issue to the team. I am glad to be able to contribute with a bug report on this recent version as I have a few use cases for this particular feature.

@mykhailosheptun
Copy link

Have the same situation.Could be great to have answer for this)

@GabrielNastase
Copy link

I'm seeing the same problem in the 12.6.0

@FranciscoKnebel
Copy link

Getting this error since updating Cypress to 12.6.0, previously using require inside cy.origin was working, but now it forces an error, because Cypress.require got reinstated in 12.6.0.

Reverting back to 12.5.* should be the only solution for now.

@jokonimo
Copy link

Is there an estimate when this will be fixed? Custom commands are unusable for us right now.

@kesirog
Copy link

kesirog commented Feb 27, 2023

Just encountered this as well. 12.7

@HesterdeTester
Copy link

HesterdeTester commented Feb 27, 2023

I have this bug as well, both in 12.6 and in 12.7 unfortunately. Exactly the same situation as described

@v7feng
Copy link

v7feng commented Feb 28, 2023

I'm meeting the same issue with cypress 12.7.0

@luke-sensei
Copy link

same issue with cypress 12.7.0, (adding experimentalOriginDependencies: true is enough)
sorry I spend more time on cypress itself than on my application tests, anyway...

@digitalgopnik
Copy link

👍 for @chrisbreiding with #25931

@chrisbreiding
Copy link
Contributor

This should be fixed by #25931 and out with the next release. Thanks for bearing with us as we work out the kinks in this experimental feature.

@simon-chen-1
Copy link

Thanks @chrisbreiding! Any idea on when the next release is?

@chrisbreiding
Copy link
Contributor

Barring any unforeseen circumstances, the next release should be on March 14th.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 14, 2023

Released in 12.8.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.8.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.origin Problems or enhancements related to cy.origin command type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.