Request: Webpack compatibility error

Created on 19 Nov 2015  ·  18Comments  ·  Source: request/request

I am using webpack to package our server-side code.When I bumped the request package from 2.65.0 to 2.67.0. I get this error:

./web/dist/server.js:153022
    module.exports = function() { throw new Error("define cannot be used indirect"); };

Error: define cannot be used indirect

webpack:///(webpack)/buildin/amd-define.js?:1
module.exports = function() { throw new Error("define cannot be used indirect"); };
stale

Most helpful comment

The workaround mentioned by @manumax worked for me without having to downgrade request module to 2.65.0. i.e.

module: {
    noParse: /node_modules\/json-schema\/lib\/validate\.js/
}

All 18 comments

I'm also getting this, this problem doesn't occur when I use version 2.65.0 of request.

It looks like this problem occurred before with other packages when compiling with webpack. They seem to have fixed some cases, but apparently not the one that's occurring in this new version of request, see: https://github.com/webpack/webpack/issues/138

Not sure what the problem is in case of request, and what the appropriate solution would be.

I am also getting this problem and it's quite frustrating to have a minor version break our builds.

It seems to be caused by upgrading http-signature from 0.11.x to 1.1.x, which is incompatible with webpack. The the _root_ module which misbehaves being json-schema, which has an untraditional AMD test: https://github.com/kriszyp/json-schema/issues/59

In order to ensure continued compatibility with webpack, I would suggest bumping back down to 0.11.x for http-signature.

Our WebPack tests are yet to be merged https://github.com/request/request/pull/1629 so if anyone of you want to contribute and fix them that would be great!

Apart from that json-schema seems to be dead. So let's see how it goes. Also currently request is not semver compliant, so it would be safer for you to stick to a fixed version in your package.json

@simov I'm don't quite understand what the issue you're referencing (#1629 Webpack karma config) has to do with this issue?

Webpack karma config have to do with the fact that if we had tests for Wepack we could have prevented this bug.

So, I though if you are using webpack, then you may want to contribute to make its support first class citizen here.

@simov I'll try to take a stab at the Webpack tests this weekend.

Thank you :+1:

I've just begun to work with javascript, so I really hope I've done everything right, in case let me now. I hopefully managed to have webpack tests working, resolving all the issues that were preventing @pho3nixf1re to complete the pull request.

I don't know if it could help in any way, but a possible workaround is explained here: webpack/webpack#138 i.e. to add the following to your webpack config:

module: {
    noParse: /node_modules\/json-schema\/lib\/validate\.js/
}

As stated before I'm quite new to javascript and I don't know if it has any implications, let me know otherwise.

As a workaround you could for now use version 2.65.0, where the problem doesn't occur..

Yep, I think you're right :) To be honest I tried to revert back to 2.65.0 but I didn't manage to make it work, I got exactly the same error. Probably I did something wrong.

Downgrading to 2.65.0 didn't work for me, but the following steps did:

  1. Manually downgrading the http-signature package to version 0.11.0
  2. Added the following additional configuration into my webpack.config.js file:
  node: {
    console: true,
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }

$ npm install --save [email protected] fixed it for me. I'm using request-promise and node 5.3.0 / npm 3.3.12.

The workaround mentioned by @manumax worked for me without having to downgrade request module to 2.65.0. i.e.

module: {
    noParse: /node_modules\/json-schema\/lib\/validate\.js/
}

@singhshashi @theopak unfortunately neither of these work - I've traced the offending module and have deleted it, fixing the problem. Still working on a way to fix it in webpack (I'm very new to it).

request-promise uses the most recent version of request i.e. "request": "^2.34"

here's the path:

node_modules\request-promise\node_modules\request\node_modules\http-signature\node_modules\jsprim\node_modules\json-schema\lib\validate.js

$ npm install --save [email protected] fixed for me as well.

I have this issue when using the google-spreadsheet package, which uses request. Unfortunately none of the fixes people have used on this page work. If I use the noParse fix I get a new error: Invalid left-hand side in assignment on this code: __webpack_require__(643) = function(ids, factory) {

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Areks picture Areks  ·  77Comments

danielgindi picture danielgindi  ·  20Comments

maiko-rocha picture maiko-rocha  ·  51Comments

dcsan picture dcsan  ·  19Comments

joe-spanning picture joe-spanning  ·  29Comments