Reputation: 3
I am developing an appilication using Node.js, react, yarn and webpack and I am not very experienced in these technologies.
I needed to use encryption and I tried to use the build-in Crypto module. The problem is that even with the simple command: crypto = require('crypto');
in my js file, webpack compilation fails with the following messages:
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/index.js
ERROR in ./node_modules/parse-asn1/aesid.json
Module build failed: SyntaxError: Unexpected token, expected ; (1:25)
> 1 | {"2.16.840.1.101.3.4.1.1": "aes-128-ecb",
| ^
2 | "2.16.840.1.101.3.4.1.2": "aes-128-cbc",
3 | "2.16.840.1.101.3.4.1.3": "aes-128-ofb",
4 | "2.16.840.1.101.3.4.1.4": "aes-128-cfb",
I have tried to use other encryption libraries like node-simple-encryptor and sjcl but I always get the same error!
I guess that it must be a webpack (version 3.5.2) problem, because when I use the same libraries in a test javascript file and run it from nodejs interactive environment, it runs OK.
Can anybody help me?
My webpack.config.js file:
const path = require('path');
module.exports = {
entry: path.resolve(__dirname, 'src', 'index.js'),
output: {
path: path.resolve(__dirname, 'output'),
filename: 'bundle.js',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.jsx']
},
module: {
rules: [
{
test: /\.js/,
use: {
loader: 'babel-loader',
options: { presets: ['react', 'es2015'] }
}
},
{
test: /\.scss/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
devServer: {
contentBase: './src',
publicPath: '/output',
historyApiFallback: true,
},
devtool: 'source-map' //Maps source files with bundle.js for debugging in the browser
};
Upvotes: 0
Views: 1724
Reputation: 246
I think the problem is that babel / webpack are treating that JSON file as a js
try using this are the first module.rules test key
test: /\.(js)$/,
instead of test: /\.js/,
Upvotes: 1