“npm install @azure/msal-browser @azure/msal-angular@latest”,但 node_modules 内没有

Posted

技术标签:

【中文标题】“npm install @azure/msal-browser @azure/msal-angular@latest”,但 node_modules 内没有【英文标题】:"npm install @azure/msal-browser @azure/msal-angular@latest" but nothing inside of node_modules 【发布时间】:2022-01-13 09:14:10 【问题描述】:

我试图在登录时包含 Azure AD,但在运行 npm install @azure/msal-browser @azure/msal-angular 以及 npm install @azure/msal-browser @azure/msal-angular@latest 之后,在 node_modules 文件夹中看不到新条目。所以当尝试导入模块时

import  MsalModule  from '@azure/msal-angular';
import  PublicClientApplication  from '@azure/msal-browser';

我收到警告 TS2307: Cannot find module '@azure/msal-browser' or its corresponding type declarations

运行命令时,它似乎安装了所有东西(我在前端所在的位置运行它,也尝试在存储前端和后端的文件夹中运行它):

npm WARN @angular/cdk@9.2.4 requires a peer of tslib@^1.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ant-design/icons-angular@9.0.1 requires a peer of @angular/common@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ant-design/icons-angular@9.0.1 requires a peer of @angular/core@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ant-design/icons-angular@9.0.1 requires a peer of @angular/platform-browser@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ant-design/icons-angular@9.0.1 requires a peer of tslib@^1.10.0 but none is installed. You must install peer dependencies yourself.
npm WARN @rollup/plugin-commonjs@15.1.0 requires a peer of rollup@^2.22.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@5.2.2 requires a peer of @angular/compiler@>=2.3.1 <10.0.0 || >9.0.0-beta <10.0.0 || >9.1.0-beta <10.0.0 || >9.2.0-beta <10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@5.2.2 requires a peer of @angular/core@>=2.3.1 <10.0.0 || >9.0.0-beta <10.0.0 || >9.1.0-beta <10.0.0 || >9.2.0-beta <10.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-zorro-antd@9.2.2 requires a peer of @angular/animations@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-zorro-antd@9.2.2 requires a peer of @angular/common@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-zorro-antd@9.2.2 requires a peer of @angular/forms@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-zorro-antd@9.2.2 requires a peer of @angular/core@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-zorro-antd@9.2.2 requires a peer of @angular/platform-browser@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-zorro-antd@9.2.2 requires a peer of @angular/router@^9.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")

+ @azure/msal-browser@2.20.0
+ @azure/msal-angular@2.0.6
updated 2 packages and audited 1717 packages in 11.119s

【问题讨论】:

您是否在前端所在的位置运行npm install?你看到包被添加到 package.json 了吗?您是否收到错误消息或警告?请向我们提供其他(相关)数据,以便我们为您提供帮助。 @rickvdbosch 我已经用更多信息更新了这个问题 您必须运行文件 package.json 所在的命令。这些命令将在本地 node_modules 文件夹中安装包 @danvid 这就是我所做的,进入 package.json 所在的前端文件夹,运行命令,它似乎通过了,但是 node_modules 文件夹中没有任何内容,当尝试将其导入应用程序时.module 它给了我上面提到的错误 【参考方案1】:

npm./node_modules 以外的目录中安装某些东西的唯一方法是设置global。运行npm config get global。如果它打印true,那么这就是你的问题。

找出globalnpm config list 的设置位置。在输出中找到global = true,然后开始在其上方的行中查找类似于; "user" config from /Users/trott/.npmrc 的行。该行将告诉您问题出在您的用户配置、项目配置还是全局配置中。您可以尝试使用npm config delete global 删除该设置,但global 设置本身可能会与该命令混淆。 (我实际上并不确定原因。我所知道的是我经历过npm config delete global 没有效果。)最好运行npm config edit 来编辑配置文件以删除该行。 (您也可以使用路径在您选择的编辑器中打开文件。除了删除global 设置行之外,请注意不要进行任何更改。)

【讨论】:

以上是关于“npm install @azure/msal-browser @azure/msal-angular@latest”,但 node_modules 内没有的主要内容,如果未能解决你的问题,请参考以下文章