Cypress: Adding external libraries not work

Created on 16 Jun 2018  路  2Comments  路  Source: cypress-io/cypress

Current behavior:

After adding new libraries it says:
Uncaught TypeError: Cannot read property 'prototype' of undefined

Desired behavior:

Use external library functions properly

Steps to reproduce:

npm install Cypress --save-dev
npm install excel --save-dev
npm install babel-cli --save-dev
npm install babel-preset-env --save-dev
npm install mocha --save-dev;

in test file in integration insert code below:
var parseExcel = require('excel/commonjs/excelParser').default;

Versions


Mac
electron 59

Most helpful comment

@kutlaykural, @EirikBirkeland is correct - you cannot require node specific libraries into browser code, but you can use cy.exec, cy.request, or the new and best cy.task for interopt with the background node process. This will enable you to do anything you'd like.

All 2 comments

I was able to reproduce this.

@kutlaykural Cypress is running in the browser and so does not have native Node.js access. The above error seems to be caused by fs$ReadStream in the below being undefined:

  var fs$ReadStream = fs.ReadStream
  ReadStream.prototype = Object.create(fs$ReadStream.prototype) // point of failure
  ReadStream.prototype.open = ReadStream$open

I suggest looking into cy.task:
https://docs.cypress.io/api/commands/task.html#
As well as cy.exec:
https://docs.cypress.io/api/commands/exec.html#

These commands can help you execute Nodejs code at the OS level and then return the results to the browser.

@kutlaykural, @EirikBirkeland is correct - you cannot require node specific libraries into browser code, but you can use cy.exec, cy.request, or the new and best cy.task for interopt with the background node process. This will enable you to do anything you'd like.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carloscheddar picture carloscheddar  路  3Comments

brian-mann picture brian-mann  路  3Comments

brian-mann picture brian-mann  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments