Describe the bug
When trying to use the @wordpress/api-request package (it's in my package.json file) I am receiving the following error during my JS application's build:
ERROR in ./node_modules/@wordpress/api-request/build-module/middlewares/http-v1.js
Module not found: Error: Can't resolve '@babel/runtime/core-js/json/stringify' in '/Users/...{path omitted}.../node_modules/@wordpress/api-request/build-module/middlewares'
@ ./node_modules/@wordpress/api-request/build-module/middlewares/http-v1.js 1:0-68
@ ./node_modules/@wordpress/api-request/build-module/index.js
@ ./assets/scripts/components/Component.jsx
@ ./assets/scripts/frontend.js
@ multi ./assets/scripts/frontend.js ./assets/styles/frontend.scss
To Reproduce
Steps to reproduce the behavior:
@wordpress/api-request in package.json like so:"dependencies": {
"@wordpress/api-request": "^1.0.0-alpha.3",
...
}
import apiRequest from '@wordpress/api-request';
apiRequest in your code, like so:apiRequest( { path: '/wp/v2/posts' } ).then( posts => {
console.log( posts );
} );
Expected behavior
apiRequest should be use-able
Am I doing something wrong here? If there are additional dependencies, shouldn't those be included in the docs or already installed as dependencies of the apiRequest package? Sorry if I'm missing something obvious.
@JulienMelissas Could you try using the @wordpress/api-fetch package? I believe it has replaced the @wordpress/api-request package.
Sorry about the confusion with the docs, @JulienMelissas. @chrisvanpatten is correct, @wordpress/api-request is deprecated in favour of @wordpress/api-fetch, as of #7566.
The npm install command is supposed to show a message to warn you @wordpress/api-request is deprecated, but it isn't showing when I test it. @ntwb, could you look into this, please?
@gziolo, @youknowriad: Could we publish an update to the @wordpress/api-request readme, showing that it's deprecated?
I've edited the handbook page to point to @wordpress/api-fetch.
Thank you both for the quick reply. Smart move to using fetch. I lost internet with some down trees due to the storm (Florence) yesterday but I'm back at it today and will give it a test.
I can confirm I didn't see a deprecation warning on npm install.
Feel free to close this out if you would like, but yes, a docs update would be great. Please let me know if I can be of help with that.
Just reporting in to say apiFetch works great (nonce middleware ftw). Thanks.
npmjs.org and npm install now show a deprecated message. 馃檪

Not sure why it wasn't originally showing the deprecated message, anyways, fixed now 馃憤
Most helpful comment
Sorry about the confusion with the docs, @JulienMelissas. @chrisvanpatten is correct,
@wordpress/api-requestis deprecated in favour of@wordpress/api-fetch, as of #7566.The
npm installcommand is supposed to show a message to warn you@wordpress/api-requestis deprecated, but it isn't showing when I test it. @ntwb, could you look into this, please?@gziolo, @youknowriad: Could we publish an update to the
@wordpress/api-requestreadme, showing that it's deprecated?I've edited the handbook page to point to
@wordpress/api-fetch.