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

Running into issues with "flask vite install" (second step of step one in example workflow) #8

Open
zacguymarino opened this issue Nov 14, 2023 · 3 comments

Comments

@zacguymarino
Copy link

zacguymarino commented Nov 14, 2023

  • Python version: 3.12.0
  • Operating System: Windows 11
  • npm --version: 10.2.0 (ran "npm --version" in console at the path of project)
  • node --version: v18.18.2 (ran "node--version" in console at the path of project)

Description

Trying to follow along the example workflow - specifically the step for installing dependencies

What I Did

>flask vite init
Vite source directory and starter content installed in 'vite'.

>flask vite install

Traceback (most recent call last):
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\flask_vite\npm.py", line 21, in run
    subprocess.run(_args, cwd=self.cwd)
  File "C:\Python312\Lib\subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python312\Lib\subprocess.py", line 1538, in _execute_child    
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:      

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Scripts\flask.exe\__main__.py", line 7, in <module>
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\flask\cli.py", line 1064, in main
    cli.main()
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\flask\cli.py", line 358, in decorator
    return __ctx.invoke(f, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\flask_vite\cli.py", line 44, in install
    npm.run("install")
  File "C:\Users\nicra\Desktop\planetDotPizza\venv\Lib\site-packages\flask_vite\npm.py", line 40, in run
    raise NPMError(dedent(msg))
flask_vite.npm.NPMError:
An error occurred while running npm.
cwd: C:\Users\nicra\Desktop\planetDotPizza\vite
npm_bin_path: npm

Flask app.py file:

from flask import Flask
from flask_vite import Vite

app = Flask(__name__)
vite = Vite(app)

@app.route('/')
def index():
    return "hello world"

if __name__ == "__main__":
    app.run()

@ningshenlo
Copy link

I also encountered the same problem and haven't found a solution yet

@melMass
Copy link

melMass commented Jan 17, 2024

Locate the binary for your npm/pnpm version and specify it in the config:

app = Flask(__name__)

# This must be set before calling Vite()
app.config[
    "VITE_NPM_BIN_PATH"
] = "C:/Users/User/scoop/apps/nvm/current/nodejs/nodejs/pnpm.cmd"

vite = Vite(app)

@amazingsey
Copy link

amazingsey commented Oct 24, 2024

Locate the binary for your npm/pnpm version and specify it in the config:

app = Flask(__name__)

# This must be set before calling Vite()
app.config[
    "VITE_NPM_BIN_PATH"
] = "C:/Users/User/scoop/apps/nvm/current/nodejs/nodejs/pnpm.cmd"

vite = Vite(app)

Thanks for the response. It works.
In my case, reading the vite npm bin path from a .env file somehow always transform the VITE_NPM_BIN_PATH value set before it got to Vite. What worked was setting the path in the code.
.env
VITE_NPM_BIN_PATH = 'C:\\Users\\<user>\\AppData\\Roaming\\npm\\pnpm.cmd'
print(VITE_NPM_BIN_PATH) === It read it as npm_bin_path: C:\\Users\\<user>\\AppData\\Roaming\ pm\\pnpm.cmd

It truncates "\n" from \npm which brought the error:
File "C:\Pythonapps\app\.venv\Lib\site-packages\flask_vite\npm.py", line 46, in run raise NPMError(dedent(msg)) flask_vite.npm.NPMError: An error occurred while running npm. cwd: C:\Pythonapps\app\client npm_bin_path: C:\\Users\\<user>\\AppData\\Roaming\ pm\\pnpm.cmd

class Config:
# VITE_NPM_BIN_PATH = environ.get("VITE_NPM_BIN_PATH") # This DID NOT WORK. 

    VITE_FOLDER_PATH = environ.get("VITE_FOLDER_PATH")
    VITE_NPM_BIN_PATH = "C:\\Users\\<user>\\AppData\\Roaming\\npm\\pnpm.cmd" # This worked!

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

4 participants