Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken when bundled with webpack #979

Closed
2 tasks done
lukechu10 opened this issue Dec 9, 2019 · 3 comments
Closed
2 tasks done

Broken when bundled with webpack #979

lukechu10 opened this issue Dec 9, 2019 · 3 comments
Labels
enhancement This change will extend Got features ✭ help wanted ✭

Comments

@lukechu10
Copy link

lukechu10 commented Dec 9, 2019

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

  • I have read the documentation.
  • 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.
@szmarczak szmarczak added enhancement This change will extend Got features ✭ help wanted ✭ labels Dec 9, 2019
@szmarczak
Copy link
Collaborator

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

@lukechu10
Copy link
Author

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

@rlecaro2
Copy link

rlecaro2 commented Jan 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This change will extend Got features ✭ help wanted ✭
Projects
None yet
Development

No branches or pull requests

3 participants