cypress: Unable to use Cypress.require within cy.origin
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
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 5
- Comments: 15 (4 by maintainers)
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.
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.