cli icon indicating copy to clipboard operation
cli copied to clipboard

Warning: Error: Netlify CLI has terminated unexpectedly when used axios

Open Xplo8E opened this issue 1 year ago • 0 comments

Describe the bug

when using axios to get external url in my router, netlify crashes and throws error

Screenshot 2024-03-24 at 8 54 44 AM

Steps to reproduce

use this router in server less express app:

router.post('/test-server', async (req, res) => {
    try {
        const response = await axios({
            url: 'https://example.com/'
        });
        console.log('Response status:', response.status);
        res.json({ status: response.status, data: response.data });
    } catch (error) {
        if (axios.isAxiosError) {
            console.log('Error from API', error);
            res.status(error.response.status).json({ error: error.response.statusText });
        } else {
            console.log('Internal error', error);
            res.status(500).json({ error: 'Something went wrong' });
        }
    }
});

run netlify serve --debug

after server started run:

curl -X POST http://localhost:8888/.netlify/functions/server/test-server

observed this error with axios, the server is working fine with node, but with netlify it giving this error.

Configuration

[build] command = "npm install && npm run build" functions = "functions"

[functions] included_files = ["./express/.json", "./.json"]

[[redirects]] from = "/server/*" to = "/.netlify/functions/server/:splat" status = 200

Environment

System: OS: macOS 14.3.1 CPU: (8) x64 Apple M1 Memory: 17.27 MB / 8.00 GB Shell: 5.9 - /usr/local/bin/zsh Binaries: Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node Yarn: 1.22.21 - /usr/local/bin/yarn npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm Watchman: 2024.01.22.00 - /usr/local/bin/watchman npmGlobalPackages: netlify-cli: 17.20.1

Xplo8E avatar Mar 24 '24 03:03 Xplo8E