Reputation: 19
I'm using webpack to compile React.js code for my Electron.js app, but when compiling using webpack it gives the following error:
ERROR in ./app/javascript/configs.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/alvinzheng/Projects/BlankReact/app/javascript/configs.js: Unexpected token (4:13)
2 | import * as path from 'path';
3 |
> 4 | const dataDir;
| ^
The configs.js file is where I store paths and urls that my app needs, and at the end of the file I export all of them using es6 syntax.
Snippet of config.js
const dataDir;
if(process.platform === "linux"){
dataDir = path.resolve(require('os').homedir(), 'FOLDER')
}else if(process.platform === "win32"){
dataDir = path.resolve(process.env.APPDATA, 'FOLDER')
}
export {dataDir}
Webpack Config:
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
mode: "production",
target: 'node',
externals: [nodeExternals()],
entry: './app/javascript/index.js',
output: {
filename: "index-bundle.js",
path: path.join(__dirname + "/app/dist/")
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
publicPath: url => '../assets/fonts/' + url
}
}
],
},
}
Babelrc:
{
"presets": ["@babel/preset-env", "@babel/react"]
}
Upvotes: 0
Views: 1033
Reputation: 8459
Constants should be initialized. Because you cannot reassign values later.
See this doc: SyntaxError: missing = in const declaration.
Should be
let dataDir;
Upvotes: 2