【问题标题】:Can't find Open when starting npm start启动 npm start 时找不到 Open
【发布时间】:2023-03-18 02:56:01
【问题描述】:

当我键入 npm start 来运行服务器时,我收到一条错误消息,提示它找不到模块 OPEN。它在 app.js 文件中调用它。这是代码文件:

const path = require('path');
const open = require('open');
const port = 5000;
const app = express();
app.get('/', function(req, res) {
    res.sendFile(path.join(__dirname, './client/index.html'))
})

app.listen(port, function(err) {
    if (err) {
        console.log(err)
    } else {
        open('http://localhost:' + port)
    }
});

/*console.log(msg);*/

这个模块应该有节点依赖吗?这就是它失败的原因吗?

【问题讨论】:

标签: node.js npm


【解决方案1】:

您需要将open 安装到本地 node_modules 文件夹,这可以使用 npm 完成。

npm install open --save

--save 标志会将其添加到您的 package.json 中(我假设您有一个使用 npm start 引用的需要 package.json 的标志),以便您以后可以运行 npm install 如果您永远移动源代码,这样它将安装那里列出的所有依赖项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-03
    • 2017-07-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多