本文介绍了在Python venv下移动node_modules位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python虚拟平台来开发Django应用程序,并且我使用babel来翻译我的JavaScript.

I have a Python venv to develop a Django application and I use babel to transpile my javascript.

当前,我在使用Python venv的同时安装了node.jsnodeenv -p.

Currently, I install node.js with nodeenv -p whilst working under my Python venv.

如果我在项目的根目录下有node_modulespackage.json文件夹,那么一切都可以正常工作,但是这弄乱了项目文件夹的结构.

Everything works fine if I have the node_modules and package.json folder at the root of my project, but it is messing up the project folder structure.

我宁愿在venv下使用node_modules:

project_folder
   |
   |- venv
         |- node_modules
         package.json

甚至:

project_folder
   |
   |- venv
         |- node
               |- node_modules
               package.json

如果将我的package.json放在venv中并从那里执行npm install,则npx babel仅在我位于venv中时才有效,而不是项目的根目录.

If I put my package.json in venv and execute npm install from there, npx babel only works if I am in venv, not a the root of the project.

从项目的根目录运行npx babel给我:

Running npx babel from the project's root directory gives me:

npx: installed 1 in 0.655s
You have mistakenly installed the `babel` package, which is a no-op in Babel 6.
Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.

    npm uninstall -g babel
    npm install --save-dev babel-cli

See http://babeljs.io/docs/usage/cli/ for setup instructions.

如何在venv文件夹下放置node_modules并能够在项目文件夹中的任何位置使用npx babel?

How can I have node_modules under the venv folder and be able to use npx babel from anywhere in the project folder?

这个问题是相关的,但我看不出如何将答案调整为nodeenv.

This question is related but I can't see how to adapt the answer to nodeenv.

推荐答案

我最终发现NODE_PATH设置为<myproject>/venv/lib/node_modules.

如果将我的package.json文件放在venv/lib/中,然后从该目录运行npm install,则可以在项目中的任何文件夹中使用npx babel.

If I put my package.json file in venv/lib/ then run npm install from this directory, I can use npx babel from any folder in the project.

这篇关于在Python venv下移动node_modules位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:25