默认情况下,npm install尝试全局安装

时间:2019-08-20 20:36:28

标签: node.js npm npm-install

在文件夹上执行npm install时,软件包安装在import { createAction, props } from '@ngrx/store'; import { AuthState } from './auth.state'; export const getAuthData = createAction('[Auth] Get authentication data'); export const authDataRetrieved = createAction('[Auth] Authentication data retrieved', props<{payload: Partial<AuthState>}>()); export const authDataNotRetrieved = createAction('[Auth] Authentication data not retrieved'); export const googleSignIn = createAction('[Auth] Google sign-in attempt start'); export const authError = createAction('[Auth] Authentication error occurred', props<{ errorMessage: string, errorCode: string }>()); 上,而不是c:\Users\<user>\node-modules

我尝试更新npm config save = false,但这不能解决问题

.\<project folder>\node-modules

在项目文件夹中执行npm install express时,我希望在项目文件夹中创建node-modules子文件夹,而express模块​​将安装在node-modules子文件夹中。但是,它是在C:\ Users \ danielk \ node-modules中创建的。

任何人都可以帮助解决什么问题以及如何解决吗?

1 个答案:

答案 0 :(得分:0)

当您执行npm install时,npm实际上将软件包安装到您当前所在的“ npm project”中。请参见以下示例:

eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (stackoverflow)
[...Truncated...]
Is this OK? (yes)

eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow
$ mkdir child

eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow
$ cd child/

eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow/child
$ npm install express
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN stackoverflow@1.0.0 No description
npm WARN stackoverflow@1.0.0 No repository field.

+ express@4.17.1
added 50 packages from 37 contributors and audited 126 packages in 3.021s
found 0 vulnerabilities


eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow/child
$ ls

eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow/child
$ ls ..
child/  node_modules/  package.json  package-lock.json

eric_@Eric-Dev-Laptop MINGW64 ~/Desktop/mixed/stackoverflow/child
$ ls ../node_modules/
accepts/              escape-html/        mime/            safer-buffer/
array-flatten/        etag/               mime-db/         send/
body-parser/          express/            mime-types/      serve-static/
bytes/                finalhandler/       ms/              setprototypeof/
content-disposition/  forwarded/          negotiator/      statuses/
content-type/         fresh/              on-finished/     toidentifier/
cookie/               http-errors/        parseurl/        type-is/
cookie-signature/     iconv-lite/         path-to-regexp/  unpipe/
debug/                inherits/           proxy-addr/      utils-merge/
depd/                 ipaddr.js/          qs/              vary/
destroy/              media-typer/        range-parser/
ee-first/             merge-descriptors/  raw-body/
encodeurl/            methods/            safe-buffer/

发生的事情是,我制作了一个stackoverflow文件夹,并在其中使用npm init初始化了一个“ npm project”,然后将cd放入了child文件夹中。当我在内部进行npm install express时,express模块将无意中安装到stackoverflow/node_module。这样一来,当您制作程序时,例如myprogram,甚至当您位于其中的某个子文件夹(例如myprogram/lib/)中并执行npm install时,该模块仍将安装到myprogram中。

将此与您的案例进行比较,这可能是因为您的C:\ Users \ danielk \已经是一个npm项目,所以当您在C:\ Users \ danielk \ Documents \ udemy_nodejs \ FirstExpressApp中时,npm会认为您在C:\ Users \ danielk \项目,然后将express模块保存在那里。

关于C:\ Users \ danielk \为何成为npm项目的原因,是您之前在此处手动进行了npm init,还是在那里您执行了第一个npm install,而C:\ Users \创建danielk \ node_modules,将其标记为npm项目。

还有另一件事,即express不是“全局”安装的,您可以通过npm install express -g进行“ global”安装(尽管Express没用全局安装)。您的情况只是软件包“安装在主目录中”。