I am trying to transpile an ES6 express app using Parceljs.
Trying to run the parcel dev server using yarn parcel index.js
displays that it is running at localhost:1234
but the page is blank. It also generates the following output when trying to run node dist/index.js
:
index.js:116
throw error;
^
TypeError: Cannot read properties of undefined (reading 'prototype')
Running yarn parcel index.js --target node
does not yield any localhost port for me to test the API with. However, the API now works as I can use node dist/index.js
to run the script but now I have to resort to npx nodemon /dist/index.js
to have file watching.
Here is the sample code. index.js
import express from "express";
const app = express();
const port = 5000;
app.get("/", (req, res) => {
res.json({ msg: "Hello!" });
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
package.json
...
"dependencies": {
"express": "^4.17.3",
"parcel": "^2.3.2",
"parcel-bundler": "^1.12.5"
}
...
I would greatly appreciate a solution that allows me to use Parceljs to watch for file updates directly, preferably with HMR.
CodePudding user response:
See issue 355: Is parcel meant to work with server-side code insluding HMR?: parcel does not (yet) support hot module reloading in nodejs.
CodePudding user response:
parcel creates a web server and serve your code but express need to be called by itself to be able create a web server and server requests. You'd better use babel & nodemon instead of parcel
I use command bellow
nodemon --exec babel-node src/index.js