serveless node 8.10 babel-runtime



一切都运行良好,但是当我尝试从 cli 调用 lambda 时,我收到错误。

{
"errorMessage": "Cannot find module 'babel-runtime/helpers/typeof'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:474:25)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)",
"Object.<anonymous> (/var/task/src/functions/mobile/register.js:341:18)",
"__webpack_require__ (/var/task/src/functions/mobile/register.js:20:30)",
"Object.<anonymous> (/var/task/src/functions/mobile/register.js:265:16)",
"__webpack_require__ (/var/task/src/functions/mobile/register.js:20:30)",
"Object.<anonymous> (/var/task/src/functions/mobile/register.js:77:24)",
"__webpack_require__ (/var/task/src/functions/mobile/register.js:20:30)"
]
}

-- 更新我不再收到此错误。但是,我确实不断收到"在部署到aws时找不到模块X错误">

我的无服务器减号函数:

service: my-api
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'local'}
region: us-west-2
role: 
timeout: 30
environment:
STAGE: ${self:provider.stage}
apiKeys: 
- apiKey-${opt:stage, 'local'}
vpc:
# removed for security
custom:
webpackIncludeModules:
packagePath: './package.json'
functions:
# Mobile Login
package: 
exclude:
- .gitignore
- .git/**
- .vscode/**
plugins:
- serverless-offline
- serverless-webpack

最后是我的网络包代码

const nodeExternals = require('webpack-node-externals');
const slsw = require('serverless-webpack');
module.exports = {
entry: slsw.lib.entries,
target: 'node',
externals: [nodeExternals()],
node: {
__dirname: false,
__filename: false
},
devtool: 'inline-source-map',
module: {
loaders: [{
test: /.js$/,
loaders: ['babel-loader'],
include: __dirname,
}]
}
};

更新:我包含顶级模块,但它们的子模块没有。

更新:

{
"errorMessage": "Cannot find module 'underscore'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:474:25)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)",
"Object.<anonymous> (/var/task/node_modules/promisified-request/promisified-request.js:4:9)",
"Module._compile (module.js:652:30)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)"
]
}

我最终通过将其添加到我的无服务器来解决这个问题。

custom:
webpackIncludeModules:
forceInclude:
- request
- underscore

可能有一种更干净的方法,但这为我解决了它。

相关内容

  • 没有找到相关文章

最新更新