Got: Broken when bundled with webpack

Created on 9 Dec 2019  ·  3Comments  ·  Source: sindresorhus/got

Describe the bug

  • Node.js version: 10.16.0
  • OS & version: Windows 10 build 1909
  • Electron version: 7.1.3
  • Typescript version: 3.7.3

I want to bundle my electron app with webpack to reduce the package size and to improve performance. However, got appears to not work with webpack.

Actual behavior

When I get the body of a request, I get tons of Unicode characters which do not mean anything:

��?��f�"y�,yv�r�Q��>�2�
^ِ>�a�xl��Z)�����֘{��Бi
V���\V����2��?��u�2�
6]x���"8��.�/���������(��$�ʱ5���86
O��b���Oe��k^�t6��B

���M
����N�F�}p�ۍaxt�ޭT�J(�Z'ODF

(This is only part of it)

There also seems to be another error where the payload of a POST request is sent as [object Object]. (See edit at end)

Expected behavior

I should get the response from the server

Code to reproduce

// index.ts
const res = got("https://www.google.com");
res.then(data => {
    console.log(data.body);
});

This code is situated in the entry point of my app.

Here is my webpack configuration:

const path = require("path");

module.exports = {
    mode: "development",
    devtool: "inline-source-map",
    entry: "./src/renderer/index.ts",
    output: {
        filename: "./dist/renderer.bundle.js",
        libraryTarget: "window"
    },
    resolve: {
        // Add `.ts` and `.tsx` as a resolvable extension.
        extensions: [".ts", ".tsx", ".js"]
    },
    module: {
        rules: [
            // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
            {
                test: /\.tsx?$/,
                include: path.resolve(__dirname, 'src'),
                loader: "ts-loader"
            }
        ]
    },
    target: "electron-renderer"
};

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got.

EDIT:

  • The issue where the payload is sent as [object Object] is actually not a problem with got but with a library I was using. Sorry for the confusion.
enhancement ✭ help wanted ✭

All 3 comments

Could you please include a repository example? I'm not familiar with webpack.

Could you please include a repository example? I'm not familiar with webpack.

I have not commited the changes yet but it should be here: lukechu10/Minecraft-Box-Launcher on the webpack-bundling branch

I was randomly checking this and found @lukechu10 probably fixed this on its end.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erfanium picture erfanium  ·  3Comments

tkoelpin picture tkoelpin  ·  3Comments

f-mer picture f-mer  ·  4Comments

sindresorhus picture sindresorhus  ·  3Comments

framerate picture framerate  ·  4Comments