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

Test generated by anchor init yields error "Provider env is not available on browser." #1145

Closed
akutruff opened this issue Dec 14, 2021 · 11 comments

Comments

@akutruff
Copy link

Description:

The project created from anchor init throws an error when trying to run the generated test.

Reproduction:

anchor init test_project
cd test_project
anchor build
anchor test

Result:

Shows the following error:

BPF SDK: /home/node/.local/share/solana/install/releases/1.8.5/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
warning: unused variable: `ctx`
 --> programs/test_project/src/lib.rs:8:23
  |
8 |     pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
  |                       ^^^ help: if this is intentional, prefix it with an underscore: `_ctx`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: `test_project` (lib) generated 1 warning
    Finished release [optimized] target(s) in 0.12s
cargo-build-bpf child: /home/node/.local/share/solana/install/releases/1.8.5/solana-release/bin/sdk/bpf/dependencies/bpf-tools/llvm/bin/llvm-readelf --dyn-symbols /workspaces/dapwords/test_project/target/deploy/test_project.so

To deploy this program:
  $ solana program deploy /workspaces/dapwords/test_project/target/deploy/test_project.so
The program address will default to this keypair (override with --program-id):
  /workspaces/dapwords/test_project/target/deploy/test_project-keypair.json
yarn run v1.22.15
warning package.json: No license field
$ /workspaces/dapwords/test_project/node_modules/.bin/ts-mocha -p ./tsconfig.json -t 1000000 'tests/**/*.ts'

Error: Provider env is not available on browser.
    at Function.env (/workspaces/dapwords/test_project/node_modules/@project-serum/anchor/src/provider.ts:68:13)
    at Suite.<anonymous> (/workspaces/dapwords/test_project/tests/test_project.ts:8:38)
    at Object.create (/workspaces/dapwords/test_project/node_modules/mocha/lib/interfaces/common.js:148:19)
    at context.describe.context.context (/workspaces/dapwords/test_project/node_modules/mocha/lib/interfaces/bdd.js:42:27)
    at Object.<anonymous> (/workspaces/dapwords/test_project/tests/test_project.ts:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Module.m._compile (/workspaces/dapwords/test_project/node_modules/ts-node/src/index.ts:439:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Object.require.extensions.<computed> [as .ts] (/workspaces/dapwords/test_project/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.exports.requireOrImport (/workspaces/dapwords/test_project/node_modules/mocha/lib/nodejs/esm-utils.js:56:20)
    at Object.exports.loadFilesAsync (/workspaces/dapwords/test_project/node_modules/mocha/lib/nodejs/esm-utils.js:88:20)
    at singleRun (/workspaces/dapwords/test_project/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/workspaces/dapwords/test_project/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@akutruff akutruff changed the title test generated by anchor init yields error "Provider env is not available on browser." Test generated by anchor init yields error "Provider env is not available on browser." Dec 14, 2021
@akutruff
Copy link
Author

akutruff commented Dec 14, 2021

Also note that running the tests in the typescript directory in the main repo also has the same failure.

https://github.com/project-serum/anchor/tree/master/tests/typescript

@akutruff
Copy link
Author

Sorry to bump, but any comment would be appreciated. This is in the main release and a blocker for starting a new project with TypeScript.

@daniel-lahlafi
Copy link

Hi managed to figure this out. For me it was the environment variable BROWSER was set to firefox. I cleared this environment variable by doing
export BROWSER=
and this worked

@bholtbholt
Copy link

@daniel-lahlafi I cleared this environment variable by doing export BROWSER=

Would you mind expanding on this? I'm running into the same issue but am not sure where to export BROWSER=. I've added it to the CLI, like BROWSER= anchor test, or BROWSER='' anchor test but neither work.

@daniel-lahlafi
Copy link

@daniel-lahlafi I cleared this environment variable by doing export BROWSER=

Would you mind expanding on this? I'm running into the same issue but am not sure where to export BROWSER=. I've added it to the CLI, like BROWSER= anchor test, or BROWSER='' anchor test but neither work.

Just run the command I wrote in the terminal before running anchor

@KingpinFisk
Copy link

export BROWER=
worked just fine here. Thanks !

@masamizu
Copy link

masamizu commented Apr 2, 2022

above comment is missing "S" in BROWSER.
export BROWSER=
worked fine also here thanks!

@Plitskine
Copy link

In most recent versions of anchor, the exported 'Provider' was moved to 'AnchorProvider'.

Had the same issue, but this was the problem !

@Yakkhini
Copy link

a little graceful command:

unset BROWSER

whatever, just make sure BROWSER environment variable unset then this issue would be fixed. ; )

@Xmohamed1X
Copy link

Error: Provider env is not available on browser.
I have the same error but in my front end anyone one can help me please
image

@endlessbuilder
Copy link

BROWSER= anchor test, or BROWSER='' anchor test
Thank you. Above command works well.

@Henry-E Henry-E closed this as completed Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants