Browserify:Can't walk dependency graph: ENOENT: no such file or directory error

问题描述 投票:0回答:0

Browserify:Can't walk dependency graph: ENOENT: no such file or directory 错误, 在尝试捆绑包含 express 和 mongoose 的 index.js 时遇到这个问题,这样我就可以避免浏览器 require is not defined 错误 这是我的 index.js 脚本

const express = require('express');
const app = express();
const port = 3000;
const mongoose = require('mongoose');

main().catch(err => console.log(err));

async function main() {
    await mongoose.connect('mongodb://127.0.0.1:27017/contact');
}

const contactSchema = new mongoose.Schema({
    name: String,
    phone: String,
    mail: String,
    desc: String
});

const contact = mongoose.model('contact', contactSchema);

// Uncomment the following line to use body-parser middleware
// const bodyparser = require("body-parser")

app.use(express.urlencoded({ extended: true }));

app.post('/contact', (req, res) => {
    const { name, phone, mail, desc } = req.body;

    const newContact = new contact({
        name,
        phone,
        mail,
        desc
    });

    newContact.save()
        .then(() => {
            res.send("Form submitted successfully");
        })
        .catch(() => {
            res.status(400).send("Unable to submit form");
        });
});

app.use(express.static('public'));

app.listen(port, () => console.log(`Server running on port ${port}`));

screenshot of this error

我之前开始学习后端,这个问题让我很沮丧,我在互联网和 youtube 上寻找解决方案,但在任何地方都找不到,非常感谢任何解决这个问题的帮助🙏🙏🙏

node.js module backend browserify referenceerror
© www.soinside.com 2019 - 2024. All rights reserved.