в терминале пишем webpack, собираем из server.js в dist.js модули. Все без ошибок
Если запустим node dist.js, то ругается и пишет, что такого модуля не находит dist.js:47
import http from 'http';
^^^^^^
SyntaxError: Unexpected token import
Мой package.json
{
"name": "js",
"version": "1.0.0",
"description": "node learn",
"main": "server.js",
"dependencies": {
"babel-loader": "^6.2.10",
"webpack": "^1.14.0"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-preset-es2015": "^6.18.0",
"babelify": "^7.3.0",
"browserify": "^13.3.0",
"http": "0.0.0",
"webpack-dev-server": "^1.16.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node_modules/.bin/webpack-dev-server"
},
"author": "",
"license": "ISC"
}
webpack.config.js
module.exports = {
entry: "./server.js",
output: {
path: __dirname,
filename: "dist.js"
}
};
server.js
import http from 'http';
console.log(http);