[英]Node.js will not install packages in project folder
I'm not sure what happened, but I've wasted six hours trying to fix Node.js as it just stopped working out of nowhere.我不确定发生了什么,但我已经浪费了六个小时试图修复 Node.js,因为它突然停止工作。 Running Windows 11 with Powershell & Git Bash .
运行Windows 11和Powershell & Git Bash 。
When I try to run npm install
in my local git repository with a Next.js application ( which I already initialized and even deleting and initializing again ), it does not work;当我尝试在本地 git 存储库中使用 Next.js 应用程序(我已经初始化甚至再次删除和初始化)运行
npm install
时,它不起作用; rather, it installs my project as a package WTFF??相反,它将我的项目安装为 package WTFF??
Whenever I run create-next-app,
it also installs the dependencies to the global folder.每当我运行
create-next-app,
它还会将依赖项安装到全局文件夹中。
node_modules
folder globallynode_modules
文件夹--location
flag at default startup to project
, but it still did not fix it.--location
标志配置为project
,但它仍然没有修复它。 Please let me know if anyone has any idea, whether right or wrong.请让我知道是否有人有任何想法,无论是对还是错。 I tried looking online for related posts but couldn't find any like mine;
我试着在网上寻找相关的帖子,但找不到像我这样的帖子; if I overlooked any, please link them below.
如果我忽略了任何内容,请在下面链接它们。 Thanks to anyone that helps, I have been losing my mind over this.
感谢任何提供帮助的人,我对此一直失去理智。
EDIT: When I set the flag for npm in the npm shim files, it does not work.编辑:当我在 npm 填充文件中为 npm 设置标志时,它不起作用。 But the workaround is to add
--location=project
every time I run an npm or npx command.但解决方法是每次运行 npm 或 npx 命令时添加
--location=project
。 I know you can set an alias to make life easier.我知道你可以设置一个别名来让生活更轻松。 How do I fix the configuration files?
如何修复配置文件?
I edited the shims located in: C:\Program Files\nodejs\node_modules\npm\bin
and C:\Program Files\nodejs
我编辑了位于以下位置的垫片:
C:\Program Files\nodejs\node_modules\npm\bin
和C:\Program Files\nodejs
I found out how to fix this problem;我发现了如何解决这个问题; it had to do with a
.npmrc
already existing in my User folder, which automatically added it to the npm config, or I'm assuming.它与我的用户文件夹中已经存在的
.npmrc
有关,它自动将其添加到 npm 配置中,或者我假设。 All I had to do with remove the .npmrc
file in my home directory and run npm config set location=project
, and it configured itself to install to the project directory by default.我所要做的就是删除主目录中的
.npmrc
文件并运行npm config set location=project
,它默认将自身配置为安装到项目目录。
.npmrc
file existed when it should not have been there, so even though I reinstalled Node, the .npmrc
never got deleted, so it always defaulted to the old configuration file and never worked. .npmrc
文件在它不应该存在的时候就存在了,所以即使我重新安装了 Node, .npmrc
也从未被删除,所以它总是默认为旧的配置文件并且从未工作过。
npm config ls
to see your configuration filenpm config ls
查看你的配置文件; "global" config from C:\Users\Ashwi\.npmrc
npm config set location=project
--location=global
flag every time you run the command.--location=global
标志。Use diffrent drive then c(sytem drive) in Windows OS.在 Windows OS 中使用不同的驱动器,然后使用 c(系统驱动器)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.