devtools icon indicating copy to clipboard operation
devtools copied to clipboard

"Open in editor" button doesn't work in Win 10 with VSCode if installation path contains spaces

Open testgit-1 opened this issue 6 years ago • 25 comments

Version

4.1.5

Browser and OS info

Chrome 70 / Windows 10

Steps to reproduce

  1. Open dev tools
  2. Select component with "Select" button
  3. Click on "Open in editor" button

What is expected?

Open component in default editor (vs code)

What is actually happening?

Got this error

"C:\Users\User\AppData\Local\Programs\Microsoft" не является внутренней или внешней командой, исполняемой программой или пакетным файлом.
		
		Could not open Home.vue in the editor.
		The editor process exited with an error: (code 1).
		
To specify an editor, sepcify the EDITOR env variable or add "editor" field to your Vue project config.

I think the problem is in default VS Code path with spaces "C:\Users\User\AppData\Local\Programs\Microsoft VS Code"

I am trying to set EDITOR variable in .env file VUE_APP_EDITOR=/c/Users/User/AppData/Local/Programs/Microsoft VS Code/Code.exe

Or use vue.config.js

const openInEditor = require('launch-editor-middleware');

module.exports = {
    configureWebpack: {
        devtool: 'source-map',
    },
    devServer: {
        before(app) {
            app.use('/__open-in-editor', openInEditor('/c/Users/User/AppData/Local/Programs/Microsoft VS Code/Code.exe'))
        }
    }
}

But the problem still remains

testgit-1 avatar Oct 30 '18 09:10 testgit-1

I think it needs to be openInEditor('C:/Users/path/to/vscode')because your vue.config.js is saying from the root of your drive, go to the folder called c which I doubt is what you want, since you want to navigate to the Users folder from root

chpxu avatar Nov 01 '18 07:11 chpxu

@beastdestroyer , thanks for the answer.

I have tried this solution.

const openInEditor = require('launch-editor-middleware');

module.exports = {
    configureWebpack: {
        devtool: 'source-map',
    },
    devServer: {
        before(app) {
            app.use('/__open-in-editor', openInEditor('C:/Users/User/AppData/Local/Programs/Microsoft VS Code/Code.exe'))
        }
    }
}

But got the same error

testgit-1 avatar Nov 01 '18 14:11 testgit-1

@testgit-1 I think it's also due to app.use('/__open-in-editor') because that part is saying, from the root of your C: Drive, find the folder called __open-in-editor. Now I don't know your file structure, but I'm guessing that folder is in the same directory as your vue.config.js so it can be either

app.use('./__open-in-editor') or app.use('__open-in-editor').

If adding that doesn't work, then I'm stumped because the only problem I could see was the paths issue. I'm not exactly a hardcore configuration dude myself so yeah xD

chpxu avatar Nov 01 '18 16:11 chpxu

Had same issue on windows 10, I actually had to rename the folder C:/Users/User/AppData/Local/Programs/Microsoft VS Code/ to C:/Users/User/AppData/Local/Programs/MicrosoftVSCode/

and then edited my PATH env variables to have the new non spaced version and all worked out. Couldn't figure out any other way. Hope this helps.

briangruber avatar Dec 10 '18 20:12 briangruber

@brianguber If that was the case, you could add %20 to the PATH since sometimes that stands for the space in Microsoft VS Code

chpxu avatar Dec 11 '18 07:12 chpxu

Can I see this problem solved in my lifetime?

kiccer avatar Sep 02 '20 07:09 kiccer

try "C:\Users\WHO\AppData\Local\Programs\Microsoft\ VS\ Code\Code.exe"

yyclvps avatar Dec 14 '20 08:12 yyclvps

try "C:\Users\WHO\AppData\Local\Programs\Microsoft\ VS\ Code\Code.exe"

What should be changed? In the code? Or in environment variables?

kiccer avatar Dec 14 '20 08:12 kiccer

try "C:\Users\WHO\AppData\Local\Programs\Microsoft\ VS\ Code\Code.exe"

What should be changed? In the code? Or in environment variables?

Try this: Go to your Windows Environment Variables and put a new variable EDITOR with that Path: C:\Users\User\AppData\Local\Programs\MicrosoftVSCode\Code.exe (Or change it that in a way, that it points on your Code.exe file). By default the "\Microsoft VS Code\" Folder has Spaces. Change that to "\MicrosoftVSCode\". That fixed it for me.

kitkid-js avatar Dec 23 '20 17:12 kitkid-js

We're having a similar issue in a couple of macs. One of them opens sublime (even though VSCODE is the default editor for .vue files) and other does nothing at all.

I think there should either be a specific mention in the README on how to set this up or provide an option in the settings where something can be done about it. For us it's actually a real pain because my fellows can't open the components directly from devtools :-(

This is a great extension and your hard work is appreciated though! Thank you!

Codermar avatar May 21 '21 18:05 Codermar

https://devtools.vuejs.org/guide/open-in-editor.html

Akryum avatar May 21 '21 19:05 Akryum

https://devtools.vuejs.org/guide/open-in-editor.html

Just to clarify it for me though. The same project does not have that setup and I've been able to open in editor since I can remember (even in multiple projects) what am I missing?

Codermar avatar May 21 '21 21:05 Codermar

@Codermar The devtools can't open your editor without the setup above. Part of it such as setting up the launch-editor middlewares are sometimes done for you (for example in vue-cli).

Akryum avatar May 21 '21 21:05 Akryum

I finally got it working using the setup option instead of the recommended before option.

const openInEditor = require('launch-editor-middleware');

module.exports = {
    devServer: {
        setup (app) {
            app.use('/__open-in-editor', openInEditor('code'))
        }
    }
}

didierdemoniere avatar May 31 '21 18:05 didierdemoniere

Thanks @didierdemoniere I confirm it worked for me too.

d9beuD avatar Jun 01 '21 08:06 d9beuD

@didierdemoniere I didn't succeed.. (இωஇ )

kiccer avatar Jun 01 '21 08:06 kiccer

@kiccer what Vue.js version are you using? It worked for me with a Vue.js v2 project.

d9beuD avatar Jun 01 '21 08:06 d9beuD

@d9beuD image I use v2 too. But this project was originally created with vue-cli2.x. My system is windows10.

kiccer avatar Jun 01 '21 08:06 kiccer

@kiccer when you type code in your powershell, does it open VSCode ?

d9beuD avatar Jun 01 '21 12:06 d9beuD

I tried it myself and solved it! @d9beuD image After I added these two lines of code, the plugin ran successfully!

// 在编辑器中打开
var openInEditor = require('launch-editor-middleware')
app.use('/__open-in-editor', openInEditor('code'))

kiccer avatar Jun 07 '21 07:06 kiccer

Works for me: before (app) { app.use('/__open-in-editor', openInEditor('"C:\\Program Files\\JetBrains\\PhpStorm 2022.1\\bin\\phpstorm64.exe"')) } in case you can't add editor to environment variables

tomgif avatar May 25 '22 10:05 tomgif

try "C:\Users\WHO\AppData\Local\Programs\Microsoft\ VS\ Code\Code.exe"

What should be changed? In the code? Or in environment variables?

Try this: Go to your Windows Environment Variables and put a new variable EDITOR with that Path: C:\Users\User\AppData\Local\Programs\MicrosoftVSCode\Code.exe (Or change it that in a way, that it points on your Code.exe file). By default the "\Microsoft VS Code" Folder has Spaces. Change that to "\MicrosoftVSCode". That fixed it for me.

it worked for me too

hrmxan avatar Dec 27 '22 05:12 hrmxan

Have others encountered this problem? I submitted a PR but it was not merged. So I published the modified version to @catnap/launch-editor-middleware. You can try this approach:

const launchMiddleware = require('@catnap/launch-editor-middleware')

module.exports = {
    devServer: {
        setup (app) {
            app.use('/__open-in-editor', launchMiddleware())
        }
    }
}

kiccer avatar May 30 '23 08:05 kiccer

image Have you ever encountered this problem?

sunpm avatar Aug 19 '23 07:08 sunpm

其他人遇到过这个问题吗?我提交了 PR 但没有被合并。所以我将修改后的版本发布到@catnap/launch-editor-middleware. 您可以尝试这种方法:

const launchMiddleware = require('@catnap/launch-editor-middleware')

module.exports = {
    devServer: {
        setup (app) {
            app.use('/__open-in-editor', launchMiddleware())
        }
    }
}

I also encountered this problem and used this method to solve it

zhao-yi-fan avatar Mar 01 '24 06:03 zhao-yi-fan