【问题标题】:Cannot find module 'winston'找不到模块“温斯顿”
【发布时间】:2013-10-23 13:34:07
【问题描述】:

我写了一个小模块,使用 winston 来记录东西。

我使用了sudo npm install -g winston(它在虚拟机上...所以我不太关心 sudo 等。

来自 npm 的日志:

winston@0.7.2 /usr/local/lib/node_modules/winston
├── cycle@1.0.2
├── stack-trace@0.0.7
├── eyes@0.1.8
├── colors@0.6.2
├── async@0.2.9
├── pkginfo@0.3.0
└── request@2.16.6 (forever-agent@0.2.0, aws-sign@0.2.0, tunnel-agent@0.2.0, oauth-sign@0.2.0, json-stringify-safe@3.0.0, cookie-jar@0.2.0, node-uuid@1.4.1, mime@1.2.11, qs@0.5.6, hawk@0.10.2, form-data@0.0.10)

当我尝试在节点中运行我的模块时,我得到:

Error: Cannot find module 'winston'
    at Function.Module._resolveFilename (module.js:331:15)
    at Function.Module._load (module.js:273:25)
    at Module.require (module.js:357:17)
    at require (module.js:373:17)
    at Object.<anonymous> (/home/name/Code/neon/neon-js-spike/logger.js:2:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Module.require (module.js:357:17)

系统版本: ubuntu 节点-v = v0.11.7-pre npm -v = 1.3.8

附:我在我的家用笔记本电脑(另一个 ubuntu vm)上试过这个并且工作正常。

【问题讨论】:

  • 您总是可以在本地安装winston,与您的程序在同一目录中。
  • 在本地安装它可以工作,但我不明白我的其他虚拟机在全球安装是如何工作的。感谢您的帮助。

标签: javascript node.js npm winston


【解决方案1】:

如果你使用

纱线

-> 在yarn run dev 之前执行yarn install

【讨论】:

    【解决方案2】:

    npm WARN winston-daily-rotate-file@3.2.3 需要 winston@^2 的对等方|| ^3 但没有安装。您必须自己安装对等依赖项。

    删除了 node_modules 文件夹 并使 npm install 成为依赖项。 成功了

    注意:在删除之前检查你有 package.json

    "温斯顿": "^2.4.1", "winston-daily-rotate-file": "^3.0.0"

    【讨论】:

      【解决方案3】:

      一般来说,缺少模块应该通过设置NODE_PATH 来解决,正如@fakewaffle 所说。当然,假设它们已安装。

      但是对于winston,这对我不起作用。出于某种原因,我不得不更新文件权限:

      chmod o+rx -R /pathto/node_modules/winston
      

      我不知道为什么权限设置不正确。此解决方案适用于 Ubuntu,可能适用于其他 linux,但不适用于 Windows。

      【讨论】:

        【解决方案4】:

        如果设置类路径的建议不起作用,可能是您需要使用 npm 链接。见:http://blog.nodejs.org/2011/04/06/npm-1-0-link/

        对于 winston,请转到脚本的根文件夹并使用以下命令:

        npm link winston
        

        【讨论】:

        • 在 windows 上,但一定要以管理员身份运行。
        【解决方案5】:

        您可能需要export NODE_PATH=/usr/local/lib/node_modules,其中/usr/local/lib/node_modules 是您的节点模块全局安装的路径。

        【讨论】:

        • 这里也一样,这适用于其他模块,但在这种情况下不适用
        猜你喜欢
        • 2013-06-01
        • 2016-08-29
        • 1970-01-01
        • 1970-01-01
        • 2023-03-11
        • 2018-11-19
        • 2014-12-10
        • 2014-01-19
        • 2012-08-27
        相关资源
        最近更新 更多