node.js - Import "require" library into ReactJS project -


i learning reactjs language , need add request library project. downloaded library github.com/request/request via npm install command , need import library project.

but when use:

import request 'request'; 

or

var request = require('request'); 

then not able build application (due errors). not sure, if can import 3rd party module (or how call) reactjs way.

can provide me little please?

==== error included ====

in .jsx file have got:

import react 'react'; var request = require('request'); import {table, tablebody, tablefooter, tableheader, tableheadercolumn, tablerow, tablerowcolumn} 'material-ui/table'; import textfield 'material-ui/textfield'; import raisedbutton 'material-ui/raisedbutton'; import floatingactionbutton 'material-ui/floatingactionbutton'; import dialogwindow '../components/dialogwindow.jsx'  import contentadd 'material-ui/svg-icons/content/add'; import playarrow 'material-ui/svg-icons/av/play-arrow'; import playlistadd 'material-ui/svg-icons/av/playlist-add'; 

as can see, request imported in 2nd line. when try build app, error:

error in ./~/forever-agent/index.js module not found: error: can't resolve 'net' in 'folder project\node_modules\forever-agent'  @ ./~/forever-agent/index.js 6:10-24  @ ./~/request/request.js  @ ./~/request/index.js  @ ./src/containers/album.jsx  @ ./src/routes.js  @ ./src/index.jsx  @ multi (webpack)-dev-server/client?http://127.0.0.1:8888 webpack/hot/dev-server react-hot-loader/patch ./src/index.jsx  error in ./~/tough-cookie/lib/cookie.js module not found: error: can't resolve 'net' in 'folder project\node_modules\tough-cookie\lib'  @ ./~/tough-cookie/lib/cookie.js 32:10-24  @ ./~/request/lib/cookies.js  @ ./~/request/index.js  @ ./src/containers/album.jsx  @ ./src/routes.js  @ ./src/index.jsx  @ multi (webpack)-dev-server/client?http://127.0.0.1:8888 webpack/hot/dev-server react-hot-loader/patch ./src/index.jsx  error in ./~/tunnel-agent/index.js module not found: error: can't resolve 'net' in 'folder project\node_modules\tunnel-agent'  @ ./~/tunnel-agent/index.js 3:10-24  @ ./~/request/lib/tunnel.js  @ ./~/request/request.js  @ ./~/request/index.js  @ ./src/containers/album.jsx  @ ./src/routes.js  @ ./src/index.jsx  @ multi (webpack)-dev-server/client?http://127.0.0.1:8888 webpack/hot/dev-server react-hot-loader/patch ./src/index.jsx  error in ./~/forever-agent/index.js module not found: error: can't resolve 'tls' in 'folder project\node_modules\forever-agent'  @ ./~/forever-agent/index.js 7:10-24  @ ./~/request/request.js  @ ./~/request/index.js  @ ./src/containers/album.jsx  @ ./src/routes.js  @ ./src/index.jsx  @ multi (webpack)-dev-server/client?http://127.0.0.1:8888 webpack/hot/dev-server react-hot-loader/patch ./src/index.jsx  error in ./~/tunnel-agent/index.js module not found: error: can't resolve 'tls' in 'folder project\node_modules\tunnel-agent'  @ ./~/tunnel-agent/index.js 4:10-24  @ ./~/request/lib/tunnel.js  @ ./~/request/request.js  @ ./~/request/index.js  @ ./src/containers/album.jsx  @ ./src/routes.js  @ ./src/index.jsx  @ multi (webpack)-dev-server/client?http://127.0.0.1:8888 webpack/hot/dev-server react-hot-loader/patch ./src/index.jsx  error in ./~/request/lib/har.js module not found: error: can't resolve 'fs' in 'folder project\node_modules\request\lib'  @ ./~/request/lib/har.js 3:9-22  @ ./~/request/request.js  @ ./~/request/index.js  @ ./src/containers/album.jsx  @ ./src/routes.js  @ ./src/index.jsx  @ multi (webpack)-dev-server/client?http://127.0.0.1:8888 webpack/hot/dev-server react-hot-loader/patch ./src/index.jsx 

looks known issue library. fix described @ https://github.com/request/request/issues/1529 (adding node configuration object webpack configuration) library working in browser.

however, might want consider alternative library such isomorphic-fetch or axios.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -