-
Notifications
You must be signed in to change notification settings - Fork 34
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
Using in browser: fs.existsSync is not a function #47
Comments
"Workaround" is to use the REST API with cy.request('PUT', 'e2e-mock:1080', {...}) |
A PR to fix the check to distinguish browser from node.js environment would be gratefully appreciated. Are you able to provide such a PR or suggest some good code to implement this? |
If you are fine with adding a single dependency, it could be done using the browser-or-node package. I could submit a PR for that. If you want to do it manually, without a dependency, I could replicate the logic from the package, but I'm not enough of an expert on node.js code to maintain that piece of code. |
Sorry for the slow response, yes your suggestion of using the browser-or-node package sounds good. |
Even though the "browser": {
"fs": false
} As per pugjs/pug-loader#8 (comment). Until then, we can workaround this with the following webpack config: node: {
fs: 'empty',
}, |
Describe the issue
When I try to use mockserver-client-node in the browser, I get the error:
This is because the check to distinguish browser from node.js environment does not consider browser bundle build systems (i.e., using require or import in browser-based environments), which is common practice by now.
What you are trying to do
I want to use mockserver in Cypress.io end-to-end tests. To dynamically set my mocks depending on the tests I am running, I want to use mockserver-client-node. In Cypress, we can easily require or import CommonJS modules which are then transpiled to run in the browser, but we cannot easily add a script tag to the page.
MockServer version
latest (5.11.1)
To Reproduce
Steps to reproduce the issue:
Expected behaviour
I expected the check in https://github.com/mock-server/mockserver-client-node/blob/master/mockServerClient.js#L27 to detect that I am running in a browser and use the XHR-based makeRequest function instead of
require('./sendRequest').sendRequest(tls, caCertPemFilePath)
.MockServer Log
Not relevant, as it doesn't get far enough to talk to MockServer
The text was updated successfully, but these errors were encountered: