Reputation: 53
I am trying to deploy my application to an AWS EC2 instance. In my local environment i can bundle everything no problem when I run webpack
. On my AWS server i cloned my repo, but when i run webpack i get
SyntaxError: Unexpected token import
.
I just checked and both my local and AWS server are running the same NPM (5.3.0) and Node (8.6.0) versions, as well as webpack versions (webpack -g).
I have .babelrc:
{
"presets": ["react", "es2015"]
}
webpack.config.babel.js:
import path from 'path';
import nodeExternals from 'webpack-node-externals';
const client = {
entry: {
js: './src/app-client.js',
},
output: {
path: path.join(__dirname, 'src', 'static', 'js'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: path.join(__dirname, 'src'),
use: {
loader: 'babel-loader',
options: 'cacheDirectory=.babel_cache',
},
},
],
},
};
export default [client];
The error is occuring on the first line of the webpack.config.babel.js
/home/ec2-user/FB/webpack.config.babel.js:1
(function (exports, require, module, __filename, __dirname) { import path from 'path';
^^^^^^
SyntaxError: Unexpected token import
Why would it work fine locally and not on AWS? Any ideas on how to fix? Thank you.
PS: My development machine is macOS and the server is Amazon linux
Upvotes: 3
Views: 1541
Reputation: 164
I was having the same problem when I use the free tier. I changed to a 4GB ram and now everything is running.
Upvotes: 0
Reputation: 13966
Replace this with
import path from 'path';
import nodeExternals from 'webpack-node-externals';
With This
var path = require('path');
var nodeExternals = require('webpack-node-externals');
And this
export default [client];
With this
module.exports = client;
Also make sure the Webpack version installed on your local machine is the same as that on your AWS server.
Also I think you are missing a preset in your .babelrc file as well
{
"presets" : ["es2015", "react", "stage-2"]
}
Upvotes: 1