我完全陷入了这个未知错误。
我安装了“ aws-amplify”以使用aws cognito并对用户进行身份验证。 但是随后出现以下错误,并且以某种方式我无法解决此问题...
有人可以帮我吗? (我尝试安装“ crypto”,但并没有帮助我解决)
TypeError: Cannot read property 'crypto' of undefined
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"homepage": "/",
"scripts": {
"dev": "export NODE_ENV=development && webpack-dev-server --mode development --port 8001 --contentBase=dist",
"build:prod": "export NODE_ENV=production && webpack --mode production",
"build:dev": "export NODE_ENV=development && webpack --mode development"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^1.0.0",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"json-loader": "^0.5.7",
"style-loader": "^0.22.0",
"url-loader": "^1.0.1",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.5"
},
"dependencies": {
"aws-amplify": "^1.0.5",
"aws-amplify-react": "^1.0.5",
"aws-sdk": "^2.292.0",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
}
}
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
resolve: {
extensions: ['.js', '.jsx']
},
entry: {
main: ['babel-polyfill', path.resolve(__dirname, 'src/index.jsx')]
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
// publicPath: './'
},
devServer: {
historyApiFallback: true
},
devtool: process.env.NODE_ENV === 'development' ? 'source-map' : false,
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: '/node_modules/',
use: [
{
loader: 'babel-loader',
options: {
presets: ['env', 'react'],
plugins: ['transform-class-properties']
}
}
]
},
{
test: /\.css$/,
use: [
'style-loader',
{ loader: 'css-loader'}
]
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
options: {},
},
{
include: path.resolve(__dirname, 'src'),
test: /\.json$/,
use: {
loader: 'json-loader',
},
},
]
},
optimization: {
splitChunks: {
name: 'vendor',
chunks: 'initial',
// test: '/node_modules/',
// enforce: true
}
},
plugins: [
new webpack.ProgressPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
}