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

Incorrect path resolve when other VS Code extensions run firebase related command #7471

Closed
jin-qin opened this issue Jul 19, 2024 · 5 comments · Fixed by #8257
Closed

Incorrect path resolve when other VS Code extensions run firebase related command #7471

jin-qin opened this issue Jul 19, 2024 · 5 comments · Fixed by #8257

Comments

@jin-qin
Copy link

jin-qin commented Jul 19, 2024

[REQUIRED] Environment info

firebase-tools: 13.13.3

Platform: macOS Sonoma 14.5

[REQUIRED] Test case

Use Orta.vscode-jest extension, configure firebase emulators:exec "jest" as its command, run jest unit test.

[REQUIRED] Steps to reproduce

  1. Install Orta.vscode-jest extension through VS Code extension marketplace.
  2. Create a bash file say test.sh, and put the following content into it:
    #!/bin/bash
    
    PARAMS="$@"
    yarn firebase emulators:exec "jest ${PARAMS}"
    
  3. In VS Code settings.json, add "jest.jestCommandLine": "./test.sh" or put ./test.sh into Jest: Jest Command Line in Jest extension settings.
  4. Configure a jest unit test
  5. Run jest unit test through CodeLens (i.e. clicking the run test button in the unit test file)

[REQUIRED] Expected behavior

Unit test is passed.

[REQUIRED] Actual behavior

Received error, test aborted:

TestRun "my-app:runTest: orta.vscode-jest:TestProvider:my-app:32 (0)" started
node:fs:448
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open '/Users/user/Projects/my-app/node_modules/firebase-tools/lib/templates/hosting/init.js'
    at readFileSync (node:fs:448:20)
    at readTemplateSync (/Users/user/Projects/my-app/node_modules/firebase-tools/lib/templates.js:17:34)
    at Object.<anonymous> (/Users/user/Projects/my-app/node_modules/firebase-tools/lib/hosting/implicitInit.js:12:56)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/user/Projects/my-app/node_modules/firebase-tools/lib/frameworks/index.js:25:24) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/user/Projects/my-app/node_modules/firebase-tools/lib/templates/hosting/init.js'
}

Node.js v20.14.0

Workaround

In fact, if I remove the following extension check insrc/templates.ts:

if (isVSCodeExtension()) {
    // In the VSCE, the /templates directory is copied into dist, which makes it
    // right next to the compiled files (from various sources including this
    // TS file). See CopyPlugin in `../firebase-vscode/webpack.common.js`.
    return resolve(__dirname, "templates", relPath);
}

the issue will be suppressed and the unit test is passed.

@joehan
Copy link
Contributor

joehan commented Jul 30, 2024

Hey @jin-qin, thanks for reporting this issue. This behavior is a consequence of some recent work we've been doing on a VSCode extension. We should looks into better ways to detect when we are running as part of VSCode. As a immediate workaround, you can manually set the env var that triggers this behavior:

VSCODE_CWD="" yarn firebase emulators:exec "jest ${PARAMS}"

@jin-qin
Copy link
Author

jin-qin commented Jul 31, 2024

It works, thank you @joehan

@i13-ctflora
Copy link

Confirming that I found the same issue trying to start firebase emulators via npm script within the Ionic vscode extension, and that adding the VSCODE_CWD='' environment variable to the npm script did alleviate the issue. The npm script ran fine originally from the command line, but gave this error when executing from the Ionic vscode extension:

Error: ENOENT: no such file or directory, open '/Users/username/.nvm/versions/node/v20.16.0/lib/node_modules/firebase-tools/lib/templates/hosting/init.js'
    at readFileSync (node:fs:448:20)

Here's my updated npm script:

  "scripts": {
    "firebase": "VSCODE_CWD='' firebase emulators:start"
  },

@MihaelIsaev
Copy link

Confirmed having problem in VSCode extension. Thanks for the workaround!

Here's how I bypassed it:

var env = process.env
env.VSCODE_CWD = ''
spawn('/path/to/firebase', ['projects:list', '--json'], { env: env })

The key point is not to forget to include the original environment variables.

@oconnorjoseph
Copy link

Ran into the same issue ourselves when invoking the Firebase emulators from inside a Playwrite global setup script after running the Playwrite test from the ms-playwright VSCode extension. Setting process.env.VSCODE_CWD = '', like for those above, resolved our issue.

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

Successfully merging a pull request may close this issue.

7 participants