1

Estoy teniendo un problema a la hora de importar axios en un proyecto en React. Resulta que al importarlo al proyecto me sale este error:

Compiled with problems:

ERROR in ./node_modules/axios/lib/adapters/http.js 11:11-26

Module not found: Error: Can't resolve 'http' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\axios\lib\adapters' Did you mean './http'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules, C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }' - install 'stream-http' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "http": false }

ERROR in ./node_modules/axios/lib/adapters/http.js 13:12-28

Module not found: Error: Can't resolve 'https' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\axios\lib\adapters'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }' - install 'https-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "https": false }

ERROR in ./node_modules/axios/lib/adapters/http.js 19:10-24

Module not found: Error: Can't resolve 'url' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\axios\lib\adapters'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }' - install 'url' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "url": false }

ERROR in ./node_modules/axios/lib/adapters/http.js 21:11-26

Module not found: Error: Can't resolve 'zlib' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\axios\lib\adapters'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "zlib": require.resolve("browserify-zlib") }' - install 'browserify-zlib' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "zlib": false }

ERROR in ./node_modules/axios/lib/adapters/xhr.js 17:10-24

Module not found: Error: Can't resolve 'url' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\axios\lib\adapters'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }' - install 'url' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "url": false }

ERROR in ./node_modules/follow-redirects/index.js 1:10-24

Module not found: Error: Can't resolve 'url' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\follow-redirects'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }' - install 'url' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "url": false }

ERROR in ./node_modules/follow-redirects/index.js 5:11-26

Module not found: Error: Can't resolve 'http' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\follow-redirects' Did you mean './http'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules, C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }' - install 'stream-http' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "http": false }

ERROR in ./node_modules/follow-redirects/index.js 7:12-28

Module not found: Error: Can't resolve 'https' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\follow-redirects' Did you mean './https'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules, C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }' - install 'https-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "https": false }

ERROR in ./node_modules/follow-redirects/index.js 9:15-41

Module not found: Error: Can't resolve 'stream' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\follow-redirects'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "stream": require.resolve("stream-browserify") }' - install 'stream-browserify' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "stream": false }

ERROR in ./node_modules/follow-redirects/index.js 11:13-30

Module not found: Error: Can't resolve 'assert' in 'C:\wamp64\www\E-Commerce-Laravel-React\front\node_modules\follow-redirects'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to: - add a fallback 'resolve.fallback: { "assert": require.resolve("assert/") }' - install 'assert' If you don't want to include a polyfill, you can use an empty module like this: resolve.fallback: { "assert": false }


Instale axios con:

npm install axios

Y como no funcionó, probé con:

npm install axios --save

Pero tampoco funcionó.

así lo importo en el proyecto:

import axios from 'axios'

Estoy utilizando React 18.

1
  • Por favor, edita la pregunta para limitarla a un problema específico con suficiente detalle para identificar una respuesta adecuada.
    – Comunidad Bot
    Commented el 26 abr. 2022 a las 8:07

1 respuesta 1

0

supongo ya esta pregunta está caducada, por la fecha de tu publicación,pero por si alguien lee la pregunta en un futuro.

Si estas en un proyecto de React (o cualquier otro framewrok-librería) e importas algo que no es nativo de la app, si no lo instalas primero, no te va a funcionar; ejemplo, si usas " import axios from 'axios' " sin haber hecho la instalación en tu máquina, no podrás importarlo.

En este caso, lo que debes hacer es instalar previamente la librería que necesites, usando NPM, Yarn, NPX, etc. Revisa cómo instalarlo dependiendo de si estas usando Linux, Windows, MAC.

Espero os ayude, saludos.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.