简体   繁体   English

npm 3全局安装的软件包不起作用

[英]npm 3 globally installed package not working

I have installed this module globally however it fails with an error when run due to a dependency error however if I run my local copy by running the command 我已经在全球范围内安装了此模块 ,但是由于依赖项错误而导致运行失败,但是如果我通过运行命令运行本地副本,则会失败

node ./bin/xl-json 

the command works. 该命令有效。 I believe when running the npm i -g xl-json command that dependencies aren't being installed properly. 我相信在运行npm i -g xl-json命令时,依赖关系未正确安装。 Any ideas why one way works and the other doesn't? 任何想法为什么一种方法有效而另一种无效?

The reason it doesn't work is because it is not [exactly] the same command you are running. 它不起作用的原因是因为它与您正在运行的命令完全不同。

If you look at the error you see: 如果查看错误,则会看到:

if (cptable === 'undefined') cptable = require('./dist/cpexcel');
                                     ^

ReferenceError: cptable is not defined

When you run the global command xl-json , the .cmd file (created by npm) takes precedence. 当您运行全局命令xl-json.cmd文件(由npm创建)优先。 iow. 督察。 npm creates a file called xl-json.cmd which is a wrapper that invokes xl-json in the bin folder. npm创建一个名为xl-json.cmd的文件,该文件是在bin文件夹中调用xl-json的包装器。

This file uses the strict option which the code should use but does not. 该文件使用代码应使用但不使用的strict选项。

Try your command with --use-strict and you should see the same error message. 尝试使用--use-strict命令,您将看到相同的错误消息。 ie: 即:

node --use-strict ./bin/xl-json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM