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

Uncaught TypeError: querystring.escape is not a function #46

Closed
tribou opened this issue Feb 1, 2017 · 10 comments
Closed

Uncaught TypeError: querystring.escape is not a function #46

tribou opened this issue Feb 1, 2017 · 10 comments

Comments

@tribou
Copy link

tribou commented Feb 1, 2017

I'm using webpack to bundle aws4, and when I set a path other than /, I get the following error:

Uncaught TypeError: querystring.escape is not a function

The stacktrace is pointing to

aws4/aws4.js

Line 228 in 0790ddc

path.push(encodeRfc3986(querystring.escape(piece)))

I tried adding the following node config to webpack (to see if it would polyfill), but it didn't seem to change anything:

node: {
  querystring: true,
}
@mhart
Copy link
Owner

mhart commented Feb 1, 2017

@tribou it's most likely the (incredibly old) version of querystring that webpack shims: https://github.com/webpack/node-libs-browser/blob/master/index.js – you can see there it's using querystring-es3 which has had this problem for years: mike-spainhower/querystring#4

I'd use this as a replacement: https://www.npmjs.com/package/querystring-browser

@mhart
Copy link
Owner

mhart commented Feb 4, 2017

Going to close this as it's an issue with the library that Webpack uses – feel free to reopen if you think there's a bug in aws4

@mhart mhart closed this as completed Feb 4, 2017
@paolavness
Copy link

For anyone running into this error with webpack, install querystring-browser and use below resolve in webpack.config.js:

  resolve: {
    alias: {
        querystring: 'querystring-browser'
      }    
  }

@Relequestual
Copy link

@paolavness This didn't solve the issue for me. I ended up getting Cannot find module "querystring" =/

@paolavness
Copy link

@Relequestual Try install querystring-browser as a local dependacy rather than global -
npm install --save querystring-browser

@Relequestual
Copy link

Yup. I did try that. Sadly no dice still. Going to find an alternative solution.
It wasn't this module I was using, it was markdown-toc.
As I don't actually want a table of contense and want to build a menu, I found another table of contense like node module which uses markdown-to-ast, so I figure I'll roll my own solution with that.

@mifi
Copy link
Contributor

mifi commented Jul 7, 2017

You don't want to change querystring.escape -> encodeURIComponent and querystring.unescape -> decodeURIComponent? That will solve the problem. And node also has these functions.
(mifi@d100d71)

I made a fork just for making this work out of the box with create-react-app & webpack, for other people who are having the same problem:
https://www.npmjs.com/package/aws41
https://github.com/mifi/aws4

@mhart
Copy link
Owner

mhart commented Jul 7, 2017

I used querystring.escape/unescape because it handles more cases:

https://github.com/nodejs/node/blob/master/lib/querystring.js#L108-L194

If we can't find any cases for aws4 where the behavior is actually different though, I'd be very happy to remove them in favor of encodeURIComponent/decodeURIComponent

@mifi
Copy link
Contributor

mifi commented Jul 7, 2017

None of the mocha tests failed when i changed to encodeURIComponent/decodeURIComponent. If there are some edge cases that will fail, then maybe we should have some tests that ensure this. I cannot think of any cases that will cause it to fail, though...

@just-boris
Copy link

just-boris commented Oct 4, 2017

By the way, there has been released a new version of underlying querystring-es3 module.

I have submitted a PR into Webpack project: webpack/node-libs-browser#70. As soon as we will manage to have this merged, the issue will be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants