Error importing super agent into react code

I have a NodeJS server code written in JSX where I import a superant in this way:

import request from 'superagent'; 

When the server starts after the build, I get the following error: TypeError: require is not a function. And this happens on the following line in my compiled code:

 var crypto = require('crypto'); 

When tracking backwards, I realized that cryptography is required "formidable", that a "super agent" is required.

I have the same superagent import in my client side javascript code, but it works great. I have decomposed JS compilation code for node (server) and client, and both of them are the same. Thus, this does not seem to be a problem with its construction.

Has anyone seen this error before and would you know what needs to be done?

+5
source share
1 answer

Found solution here:

https://github.com/visionmedia/superagent/wiki/Superagent-for-Webpack

Adding the specified plugin to the web package solved the problem.

+5
source

Source: https://habr.com/ru/post/1240140/


All Articles