At the moment all my module in my nodejs server are imported as require() ie:
let path = require(\'path\');
let express = require(\'express\');
let http = re
It works in the webpack situation because the code is run through babel. You can run your node.js code through babel.
Install the babel cli if you don't have it
npm install --save-dev babel-cli
Then run your code like this:
./node_modules/.bin/babel-node server.js
Or put it in package.json.
{
"scripts": {
"start": "babel-node server.js"
}
}
By default, you’ll be using ES5 and it’ll be required to use require (ja ja) to pull in modules. As we move forward with ES6 and beyond, it’s really best for us to start using ES6 classes as well as import and export statements. To do this, we’ll need Babel in order to interpret our ES6 syntax.
1. npm install --save-dev babel-cli
2. npm install --save-dev babel-preset-es2015
3. Lets pull in both ‘babel-cli and babel preset es2015” as dev dependencies as well as add the .babelrc file
{
"presets": ["es2015"]
}
The issue was gone, if you do as above steps`enter code here`
more infor please see:https://codebrains.io/setting-up-express-with-es6-and-babel/