node.js - sls 离线云端命令给出错误 webpack 插件找不到配置文件... webpack.config.js
问题描述
我正在开发一个使用 AWS Lambda 和无服务器 (sls)技术的项目。当尝试运行npm start
which runssls offline cloudside
我得到错误:
The webpack plugin could not find the configuration file at: c:\Play\MyProj\src\myproj-backend\services\user-service\d:\Play\MyProj\src\myproj-backend\services\user-service\node_modules\serverless-bundle\src\webpack.config.js
完整的输出是:
npm start
> users-service@1.0.0 start c:\Play\MyProj\src\myproj-backend\services\user-service
> sls offline cloudside
Serverless: Deprecation warning: Starting with version 3.0.0, following property will be replaced:
"provider.iamRoleStatements" -> "provider.iam.role.statements"
More Info: https://www.serverless.com/framework/docs/deprecations/#PROVIDER_IAM_SETTINGS
Serverless: Deprecation warning: Resolution of lambda version hashes was improved with better algorithm, which will be used in next major release.
Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"
More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Loading cloudside resources for 'users-service-dev' stack.
Serverless Error ----------------------------------------
The webpack plugin could not find the configuration file at: c:\Play\MyProj\src\myproj-backend\services\user-service\d:\Play\MyProj\src\myproj-backend\services\user-service\node_modules\serverless-bundle\src\webpack.config.js
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
Operating System: win32
Node Version: 12.16.2
Framework Version: 2.30.2
Plugin Version: 4.5.1
SDK Version: 4.2.0
Components Version: 3.7.3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! users-service@1.0.0 start: `sls offline cloudside`
npm ERR! Exit status 1
但奇怪的是,同一个 git 项目可以在我使用的另一个开发盒上运行。 知道为什么这不起作用吗?
解决方案
其原因很奇怪,很可能与涉及 SYMLINKD 目录时 nodejs 在 windows 上解析文件的方式有关。没有其他人可能会出现此错误,但他们可能会因此发布我的答案。
我的主机有两个磁盘:c: 和 d:。为了与我的其他机器保持一致,我在 c:\play 上完成了所有工作,这样对我来说更简单。在有问题的主机上,我创建了一个 SYMLINKD from c:\play
to d:\play
。下面是dir
显示我在说什么的命令的输出:
c:\>dir
04/12/2020 07:59 PM <SYMLINKD> Play [d:\Play]
因此,当我进入 c:\Play 目录时,它实际上进入了 d:\Play 目录,因此以下两个命令将我放入完全相同的目录:
cd /d c:\play\myproj\myproj-backend-services\user-service
cd /d d:\play\myproj\myproj-backend-services\user-service
当我运行文件sls offline cloudside
时webpack.config.js
找不到。构建正在寻找文件:
c:\Play\MyProj\src\myproj-backend\services\user-service\d:\Play\MyProj\src\myproj-backend\services\user-service\node_modules\serverless-bundle\src\webpack.config.js
经过仔细检查,我意识到文件名已损坏,并且某些东西将两个目录粘在一起。即这两个字符串被粘在一起以制作webpack.config.js
文件。
c:\Play\MyProj\src\myproj-backend\services\user-service\
d:\Play\MyProj\src\myproj-backend\services\user-service\node_modules\serverless-bundle\src\webpack.config.js
该webpack.config.js
文件确实存在,当我更改为 D: 驱动器时,一切都按预期工作。 警告我的错误输出行是:
The webpack plugin could not find the configuration file at: c:\Play\MyProj\src\myproj-backend\services\user-service\d:\Play\MyProj\src\myproj-backend\services\user-service\node_modules\serverless-bundle\src\webpack.config.js
因此,如果 Windows 中的其他任何人使用过 SYMLINKD(请参阅mklink /d),那么您也可能会遇到这个问题。
正常工作时(从 D: 驱动器运行),输出为:
d:\Play\MyProj\src\myproj-backend\services\user-service>npm start
> users-service@1.0.0 start d:\Play\MyProj\src\myproj-backend\services\user-service
> sls offline cloudside
Serverless: Deprecation warning: Starting with version 3.0.0, following property will be replaced:
"provider.iamRoleStatements" -> "provider.iam.role.statements"
More Info: https://www.serverless.com/framework/docs/deprecations/#PROVIDER_IAM_SETTINGS
Serverless: Deprecation warning: Resolution of lambda version hashes was improved with better algorithm, which will be used in next major release.
Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"
More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Loading cloudside resources for 'users-service-dev' stack.
Serverless: Bundling with Webpack...
Serverless: Watching for changes...
offline: Starting Offline: dev/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:3002
offline: Function names exposed for local invocation by aws-sdk:
* createUser: users-service-dev-createUser
* getUser: users-service-dev-getUser
* signup: users-service-dev-signup
* login: users-service-dev-login
┌──────────────────────────────────────────────────────────────────────────────┐
│ │
│ POST | http://localhost:4321/dev/user/create │
│ POST | http://localhost:4321/2015-03-31/functions/createUser/invocations │
│ GET | http://localhost:4321/dev/user │
│ POST | http://localhost:4321/2015-03-31/functions/getUser/invocations │
│ POST | http://localhost:4321/dev/user/signup │
│ POST | http://localhost:4321/2015-03-31/functions/signup/invocations │
│ POST | http://localhost:4321/dev/user/login │
│ POST | http://localhost:4321/2015-03-31/functions/login/invocations │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
offline: [HTTP] server ready: http://localhost:4321 �
offline:
offline: Enter "rp" to replay the last request
推荐阅读
- azure - 通过自定义策略将多个社交帐户链接到 Azur B2C 本地帐户
- c# - 如何使用 GoogleApiAvailability?我想使用它时总是收到错误消息
- python - 在 Anaconda 提示符中更新软件包时的 RemoveError
- r - 使用 R 和带有完整链接方法的凝聚层次聚类 (AHC) 技术绘制树状图
- node.js - 无法将 tesseract 函数的结果值存储到异步函数内的全局变量中
- java - 我可以在 java 上动态地填充 args[] 参数吗?
- ssh - 为 confd netconf ssh 连接设置 ipv4 和 ipv6
- javascript - 停止离子变化激发,直到从存储中加载值
- html - 如何使用 hr 获取他父 div 的全宽?
- c# - 做项目学习