Moving node_modules location under a Python venv

余生颓废 提交于 2019-12-11 14:47:42

问题


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

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

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.

I would rather have node_modules under venv:

project_folder
   |
   |- venv
         |- node_modules
         package.json

or even:

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

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.

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.

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

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


回答1:


I eventually figured out that NODE_PATH is set to <myproject>/venv/lib/node_modules.

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.



来源:https://stackoverflow.com/questions/50139016/moving-node-modules-location-under-a-python-venv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!