我正在尝试打包一个 monorepo 应用程序以使用无服务器进行部署。monorepo 使用 yarn 工作空间和 lerna。为了创建用于部署的包,我们使用 webpack。项目结构如下:
这是monorepo中的项目结构:
common
- shared_project_1
-- package.json
- shared_project_2
-- package.json
服务
- service_1
-- package.json
--
serverless.yml -- webpack.config.js
- service_2
-- package.json
--
serverless.yml -- webpack .config.js
package.json
lerna.json
commom/shared_project_1/package.json:
"private": true,
"dependencies": {
"bcrypt": "^3.0.4"
}
服务/service_1/package.json:
"private": true,
"scripts": {
"build": "serverless webpack --stage development"
}
服务/service_1/serverless.yml:
service:
name: service-1
provider:
name: aws
runtime: nodejs8.10
custom:
webpack:
includeModules:
forceExclude:
- aws-sdk
packager: yarn
functions:
<functions here>
package:
exclude:
- coverage/**
plugins:
- serverless-webpack
包.json:
"private": true,
"workspaces": {
"packages": [
"services/*",
"common/*"
]
},
"scripts": {
"build": "export NODE_ENV=development && lerna run --concurrency 1 build"
}
lerna.json:
{
"packages": [
"services/*"
],
"version": "1.0.0",
"npmClient": "yarn",
"useWorkspaces": true
}
当无服务器到达“无服务器:与 Webpack 捆绑...”时,我得到的错误是:
/Users/me/Projects/monorepo/node_modules/bcrypt/bcrypt.js 中的警告 6:15-36 关键依赖项:依赖项的请求是一个表达式 @ /Users/me/Projects/monorepo/common/shared_project_1/src/表/users.js @ /Users/me/Projects/monorepo/common/shared_project_1/src/connection.js @ ./src/dashboard-snapshots.js
/Users//Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/pre-binding.js 中的警告 20:22-48 关键依赖:依赖的请求是一个表达式 @ /Users/me /Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/node-pre-gyp.js @ /Users/me/Projects/monorepo/node_modules/bcrypt/bcrypt.js @ /Users/me/Projects /monorepo/common/shared_project_1/src/tables/users.js @ /Users/me/Projects/monorepo/common/shared_project_1/src/connection.js @ ./src/dashboard-snapshots.js
/Users/me/Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/versioning.js 中的警告 17:20-67 关键依赖项:依赖项的请求是一个表达式 @/Users/我/项目/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/pre-binding.js @ /Users/me/Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/node -pre-gyp.js @ /Users/me/Projects/monorepo/node_modules/bcrypt/bcrypt.js @ /Users/me/Projects/monorepo/common/shared_project_1/src/tables/users.js @ /Users/me/项目/monorepo/common/shared_project_1/src/connection.js @ ./src/dashboard-snapshots.js
/Users/me/Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js 中的警告:找不到模块:错误:无法解析“/Users/me/”中的“npm”项目/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util' @ /Users/me/Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js @ /Users/me/Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp/lib 同步 ^./.*$ @ /Users/me/Projects/monorepo/node_modules/bcrypt/node_modules/node-pre-gyp /lib/node-pre-gyp.js @ /Users/me/Projects/monorepo/node_modules/bcrypt/bcrypt.js @ /Users/me/Projects/monorepo/coinfo 访问https://yarnpkg.com/en/docs /cli/run获取有关此命令的文档。
我已尝试根据其他问题的建议将 bcrypt 添加到 nohoist 工作区配置中,但这只会更改错误消息中的路径。我已经全局安装了 node-pre-gyp 和 node-gyp;没什么区别。显然,我不明白这些部分是如何组合在一起的。我需要进行哪些更改才能使工作区正确捆绑 bcrypt 依赖项以部署到 AWS 中?