I am new to Express, so forgive me if this is a simple one. I have a React project and I am trying to add Express to it. I have added a .js file that begins with the following line to import express:
var express = require('express');
However, this throws an error.
Error
request.js:31 Uncaught TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (request.js:31)
at __webpack_require__ (bootstrap 2c79a52…:555)
at fn (bootstrap 2c79a52…:86)
at Object.<anonymous> (express.js:20)
at __webpack_require__ (bootstrap 2c79a52…:555)
at fn (bootstrap 2c79a52…:86)
at Object.<anonymous> (index.js:11)
at __webpack_require__ (bootstrap 2c79a52…:555)
at fn (bootstrap 2c79a52…:86)
at Object.<anonymous> (myNewFile.js:1)
Note: line 1 of myNewFile.js
is var express = require('express');
I did try npm install express
so I should have access to express and it should be up to date, but it seems that I still get this error.
How can I resolve this error and why is it occurring?
Thanks.
You need to specify target
in webpack config:
target: 'node'
And this will work only on server side as node.js program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With