错误:找不到模块'xml2json'

5
运行我的项目包时,我遇到了上述标题错误,之后我尝试使用以下命令安装该软件包:npm install xml2json。但是,我只收到了以下错误,请给我建议或想法以解决这个问题...
D:\xampp\htdocs\podio>npm install xml2json

> node-expat@2.3.16 install D:\xampp\htdocs\podio\node_modules\node-expat
> node-gyp rebuild


D:\xampp\htdocs\podio\node_modules\node-expat>if not defined npm_config_node_gyp
 (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_mo
dules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
Warning: Missing input files:
D:\xampp\htdocs\podio\node_modules\node-expat\build\deps\libexpat\..\..\..\deps\
libexpat\version.c
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe".
 To fix this, 1) install the .NET Framework 2.0 SDK, 2) install Microsoft Visua
l Studio 2005 or 3) add the location of the component to the system path if it
is installed elsewhere.  [D:\xampp\htdocs\podio\node_modules\node-expat\build\b
inding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\
npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_proces
s.js:219:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodej
s\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd D:\xampp\htdocs\podio\node_modules\node-expat
gyp ERR! node -v v6.11.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install" "xml2json"
npm ERR! node v6.11.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! node-expat@2.3.16 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-expat@2.3.16 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-expat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-expat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-expat
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\xampp\htdocs\podio\npm-debug.log

编辑:: 1

我将Visual Studio 2005更新到2012后,当我运行npm install xml2json和npm install xml2json --unsafe-perm时,出现以下错误:

C:\Users\Desktop\New folder\action>npm install xml2json

> node-expat@2.3.16 install C:\Users\Hoffensoft\node_modules\node-expat
> node-gyp rebuild


C:\Users\Hoffensoft\node_modules\node-expat>if not defined npm_config_node_gyp (
node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modu
les\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
Warning: Missing input files:
C:\Users\Hoffensoft\node_modules\node-expat\build\deps\libexpat\..\..\..\deps\li
bexpat\version.c
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
  xmlparse.c
  xmltok.c
  xmlrole.c
c:\users\hoffensoft\node_modules\node-expat\deps\libexpat\lib\siphash.h(201): w
arning C4244: 'initializing' : conversion from '__int64' to 'char', possible lo
ss of data (..\..\..\deps\libexpat\lib\xmlparse.c) [C:\Users\Hoffensoft\node_mo
dules\node-expat\build\deps\libexpat\expat.vcxproj]
  win_delay_load_hook.cc
  expat.vcxproj -> C:\Users\Hoffensoft\node_modules\node-expat\build\Release\\l
  ibexpat.lib
  node-expat.cc
  win_delay_load_hook.cc
C:\Users\Hoffensoft\node_modules\nan\nan.h(75): fatal error C1060: compiler is
out of heap space (..\node-expat.cc) [C:\Users\Hoffensoft\node_modules\node-exp
at\build\node_expat.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\
npm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_proces
s.js:219:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodej
s\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Hoffensoft\node_modules\node-expat
gyp ERR! node -v v6.11.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Hoffensoft\pac
kage.json'
npm WARN Hoffensoft No description
npm WARN Hoffensoft No repository field.
npm WARN Hoffensoft No README data
npm WARN Hoffensoft No license field.
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "install" "xml2json"
npm ERR! node v6.11.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! node-expat@2.3.16 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-expat@2.3.16 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-expat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-expat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-expat
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Hoffensoft\Desktop\New folder\action\npm-debug.log

预先感谢,Gopal R


运行以下命令进行安装:npm install xml2json --save - Mohammad Raheem
没有@MohammadRaheem,仅加--save参数依然会出现相同的错误,这只是在package.json文件中保存名称而已。 - R.G.Krish
你正在使用 Angular 2/4 吗? - Darshan Vachhani
不是 @D.V,这是一种中间件应用程序。 - R.G.Krish
删除 node modules 目录,使用 npm cache clean --force 命令清除 npm-cache,然后尝试通过运行 npm install xml2json --unsafe-perm 命令安装相同的包,如果在相同的依赖项处中断,则使用 npm install node-expat@2.3.16 --unsafe-perm 命令。 - Suhas Gavad
显示剩余9条评论
2个回答

4

我已经解决了这个问题
使用下面的命令:npm install xml2json-light
并把let parser = require('xml2json');修改为let parser = require('xml2json-light');
这对我有用


最初的回答

0
我已经解决了这个问题。如果你注意到命令的这一部分 else (node "" rebuild ),我认为发生的是它错误地将 if not defined npm_config_node_gyp 评估为 false,并尝试运行空值而不是 node-gyp。你需要做的是定义你的 npm_config_node_gyp 变量。你可以这样做: export npm_config_node_gyp=<PATH_TO_NODE_GYP_PACKAGE_FOLDER> 记住,在 Windows 中需要双反斜杠。对于我来说,看起来像这样: export npm_config_node_gyp=C:\\Users\\781990\\AppData\\Roaming\\nvm\\v6.11.0\\node_modules\\node-gyp

编辑: 修复后还有一个步骤。在执行代码时,缺少 expat 绑定。要解决此问题,请将 bin 文件夹和 node-gyp 可执行文件添加到 npm_config_node_gyp 变量中,并在 node_modules\node-expat 文件夹中运行 node-gyp rebuild。例如: export npm_config_node_gyp=C:\\Users\\781990\\AppData\\Roaming\\nvm\\v6.11.0\\node_modules\\node-gyp\\bin\\node-gyp.js cd node_modules\node-expat node-gyp rebuild


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接