Closed abid71 closed 6 years ago
It looks like browserify is ignoring the "browser" field in package.json for some reason. What does your require
call look like. If you do require('sync-request')
, browserify should pick up sync-request/lib/browser.js
but if that's not working, you could try explicitly requiring require('sync-request/lib/browser')
?
Thank you for your support!
I think you have been pinpoint my exact issue. Initially, I haven't added "browser" field in package.json but now I have added it as "browser": { "./node_modules/sync-request/browser.js": "./browser/lib/shim/browser.js" }, //in my case "browser.js" reside in "sync-request/"
instead of in "sync-request/lib"
And after executing my code again by using the grunt-browserify face the following issue: "ENOENT: no such file or directory, lstat 'D:\protractorSol\gitLabRepos\myzameenprotractorsol\browser\lib\shim'"
as "\browser\lib\shim" is the value of key "./node_modules/sync-request/browser.js" in "browser" field in package.json
You don't need to add a "browser"
field. If you install the current version of sync-request, it includes that field for you. Please check that you are using sync-request 6.0.0 as I'm not supporting older versions.
updated sync-request to v 6.0.0 but still same is appearing as shown screenshot in my first comment :(
If you add sync-request 6.0.0 you will definitely have a lib
folder that has a browser.js
file and an index.js
file.
are you using yarn or npm? You will also need to delete the browser
field you added.
I'm using npm and have already deleted browser
field from package.json.
after upgrading the sync-request
to v 6.0.0 browser.js
and index.js
contained in lib
folder.
That looks correct. Is browserify now picking up the ./lib/browser.js
file? If not, what version of browserify are you using, and what does your require
call look like.
How can I know that browserify now picking up the ./lib/browser.js file? I'm using "grunt-browserify": "^5.2.0"
instead of standalone browserify (unable to use it due to issue as: "Error: Cannot find module './C:/Users/Abid Ali/AppData/Roaming/npm/node_modules/browserify/node_modules/is-buffer/index.js' from 'D:\protractorSol\gitLabRepos\myzameenprotractorsol\node_modules\http-signature\lib'").
require
as var sync_req = require('sync-request');
for nodejs usage.
right, that require
call is fine, but it's definitely something odd about your browserify setup. It could be some kind of bug in grunt-browserify. It could be a bug in browserify itself, but it seems way more likely that you've got a broken node config installed somehow, perhaps with some weird env vars set, or disabling the browser field somehow. I'm going to close this as it doesn't look like the problem is sync-request.
You could try opening an issue in grunt-browserify or browserify, but you might have better luck asking why the "browser" field isn't working on stackoverflow (or google for that matter). In the mean time, require('sync-request/lib/browser')
will probably work as a workaround.
i'm running my Mocha scripts via Browserify in browser but got the following error in browser's console:
"Uncaught Error: Sync-request requires node version 0.12 or later. If you need to use it with an older version of node you can
npm install sync-request@2.2.0
, which was the last version to support older versions of node."However installed nodejs's version on machine is `v9.5.0'