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

Runtime errors in browser #1638

Closed
rzcoder opened this issue Mar 17, 2022 · 1 comment
Closed

Runtime errors in browser #1638

rzcoder opened this issue Mar 17, 2022 · 1 comment
Labels

Comments

@rzcoder
Copy link

rzcoder commented Mar 17, 2022

I'm getting runtime errors when compile project with anchor by webpack. In investigation I found this piece of code in npm module

dist/cjs/utils/common.js:

/**
 * Returns true if being run inside a web browser,
 * false if in a Node process or electron app.
 */
exports.isBrowser = process.env.BROWSER ||
    (typeof window !== "undefined" && !((_a = window.process) === null || _a === void 0 ? void 0 : _a.hasOwnProperty("type")));

Looks like it will always fail in browser

@acheroncrypto
Copy link
Collaborator

/**
* Returns true if being run inside a web browser,
* false if in a Node process or electron app.
*/
export const isBrowser =
process.env.ANCHOR_BROWSER ||
(typeof window !== "undefined" && !window.process?.hasOwnProperty("type"));

typeof window !== "undefined" && !window.process?.hasOwnProperty("type") should return true in browsers. You can try it by opening the browser console and executing this code.

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

No branches or pull requests

2 participants