【发布时间】:2018-01-28 12:40:24
【问题描述】:
我正在使用 Node.js、react、yarn 和 webpack 开发一个应用程序,但我对这些技术不是很有经验。
我需要使用加密,我尝试使用内置 Crypto 模块。问题是即使在我的 js 文件中使用简单的命令:crypto = require('crypto');,webpack 编译也会失败并显示以下消息:
@ 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",
我曾尝试使用其他加密库,例如 node-simple-encryptor 和 sjcl,但我总是遇到同样的错误!
我猜应该是webpack(3.5.2版)的问题,因为当我在一个测试javascript文件中使用相同的库并从nodejs交互环境运行时,它运行正常。
谁能帮帮我?
我的 webpack.config.js 文件:
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
};
【问题讨论】:
标签: node.js webpack cryptography