gpt4 book ai didi

node.js - 在 Windows 7 上找不到模块 'connect'

转载 作者:太空宇宙 更新时间:2023-11-03 22:16:44 26 4
gpt4 key购买 nike

请看下面:

    C:\Program Files\nodejs>npm -g install connect
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/finalhandler/0.1.0
npm http GET https://registry.npmjs.org/debug/1.0.4
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/finalhandler/0.1.0
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/debug/1.0.4
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/debug/1.0.4
npm http GET https://registry.npmjs.org/finalhandler/0.1.0
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/ms/0.6.2
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/ms/0.6.2
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/ms/0.6.2
connect@3.1.1 C:\Users\u166824\AppData\Roaming\npm\node_modules\connect
├── utils-merge@1.0.0
├── parseurl@1.3.0
├── debug@1.0.4 (ms@0.6.2)
└── finalhandler@0.1.0 (escape-html@1.0.1)

C:\Program Files\nodejs>

我的 Connect 模块安装成功吗?我如何知道“Connect”是否已正确安装?

此外,当我尝试启动服务器时,出现以下错误:

    C:\Program Files\nodejs>node server.js

module.js:340
throw err;
^
Error: Cannot find module 'connect'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Program Files\nodejs\server.js:1:77)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

我的server.js中的代码如下:

    var connect = require('connect');

connect.createServer(
connect.static("../angularjs")

).listen(5000);

有什么办法无法连接吗?谢谢!

最佳答案

您无法 require() 在 npm 中使用 -g 标志安装的模块。删除 -g 标志:npm install connect-g 用于安装提供命令行实用程序的模块,例如 express-generator 模块。

此外,您确实不应该在项目中使用 C:\Program Files\nodejs 因为 npm 会将模块安装在当前工作目录的子目录中...

关于node.js - 在 Windows 7 上找不到模块 'connect',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25647276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com