aws cognito 中的一个模块丢失:errorMessage": "Cannot find module './lib/browser_loader

A module in aws cognito is missing: errorMessage": "Cannot find module './lib/browser_loader

我正在尝试为我的项目使用 cognito,但是当我按照解释的所有必要设置进行操作时,我无法 运行 它并且在我的 lamda 测试控制台中出现以下错误:

{
  "errorMessage": "Cannot find module './lib/browser_loader'",
  "errorType": "Error",
  "stackTrace": [
  "Function.Module._load (module.js:417:25)",
  "Module.require (module.js:497:17)",
   "require (internal/module.js:20:19)",
   "Object.<anonymous> (/var/task/index.js:3651:1)",
    "__webpack_require__ (/var/task/index.js:20:30)",
   "webpackUniversalModuleDefinition (/var/task/index.js:149:28)",
   "Object.<anonymous> (/var/task/index.js:156:3)",
   "__webpack_require__ (/var/task/index.js:20:30)",
   "Object.<anonymous> (/var/task/index.js:75:18)"
  ]
 }

我按照以下link中提到的说明进行操作:https://github.com/aws/amazon-cognito-identity-js

所以我先用webpack和jsonloader来改造代码。这是我的 webpack 代码:

{
  "name": "bnitjouathprovider",
  "version": "0.0.1",
  "description": "provide the server for password management using cognito",
  "main": "index.js",
  "scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
   "build": "webpack"
  },
  "author": "Hamed Minaee",
  "license": "ISC",
  "devDependencies": {
   "amazon-cognito-identity-js": "^1.18.0",
   "aws-sdk": "git://github.com/chrisradek/aws-sdk-js.git#webpack",
   "babel-core": "^6.24.1",
   "babel-loader": "^7.0.0",
   "babel-preset-es2015": "^6.24.1",
   "babel-preset-stage-0": "^6.24.1",
   "brfs": "^1.4.3",
   "json-loader": "^0.5.4",
   "transform-loader": "^0.2.4",
   "webpack": "^3.0.0-rc.1"
  },
 "dependencies": {
    "amazon-cognito-identity-js": "^1.18.0"
 },
 "babel": {
   "presets": [
    "es2015",
     "stage-0"
   ]
 }
}

这是我的 webpack.config:

var path = require("path");
var DIST_DIR = path.resolve(__dirname, "dist");
module.exports = {
// Example setup for your project:
// The entry module that requires or imports the rest of your project.
// Must start with `./`!
entry: './',
// Place output files in `./dist/my-app.js`
output: {
    path: DIST_DIR,
    filename: 'index.js'
},
module: {
    noParse: [
        /aws\-sdk/,
    ],
    loaders: [
        {
            test: /\.json$/,
            loader: 'json'
        }
    ]
}
 };

所以现在我假设我的代码应该可以转换了。这是我的代码:

var AWSCognito = require('amazon-cognito-identity-js/dist/amazon-cognito-
 identity'); 


 exports.handler = function (event, context, callback) {
     registerUset();
     callback(null, "some success message");

 }


 var registerUset = function () {

 }

如您所见,它只是一个简单的 java 脚本代码,其中没有任何内容。现在,当我这样做时: npm 运行 build 我看到编译后的 js 文件并且没有收到任何错误。 但是,当我压缩 js 和节点模块文件夹并在 lambda 控制台中上传和测试它时,出现以下错误:

"errorMessage": "Cannot find module './lib/browser_loader'"

完整堆栈在 post 的开头 posted。对我来说这没有意义。是 aws 错误还是我遗漏了什么?

我找到了我的问题的解决方案,以防有人遇到同样的问题:

感谢:

http://www.rricard.me/es6/aws/lambda/nodejs/2015/11/29/es6-on-aws-lambda.html

所以基本上我需要同时使用 babel 和 json 作为加载器,所以解决解决方案的关键部分是:

module: {
 loaders: [
   {
     test: /\.js$/,
     exclude: /node_modules/,
     loader: 'babel',
     query: {
     presets: ['es2015'],
       plugins: ['syntax-flow', 'transform-flow-strip-types']
      }
    },
     {
      test: /\.json$/,
      loader: 'json'
     }
   ]
   }