Error: Cannot find module '@serverless/utils/log' after installing and enabling
Closed this issue ยท 4 comments
Describe the bug
After installing the plugin with npm install --dev serverless-better-credentials
and adding it as first plugin in serverless.yml
, serverless
command produces an error Error: Cannot find module '@serverless/utils/log'
(full error below).
I also tried serverless plugin install --name serverless-better-credentials
and got the same result.
If I remove it from plugins, sls
command works again.
To Reproduce
- Create serverles project (I used aws-python template)
- Install this plugin
- Run
serverless
Expected behavior
No error
Desktop (please complete the following information):
- OS: MacOs 12.6
- Version 1.1.3
- Serverless Version 3.23.0
Node version v14.19.1
Additional context
serverless version
serverless --version
Framework Core: 3.23.0
Plugin: 6.2.2
SDK: 4.3.2
serverless.yml
service: sls-project
frameworkVersion: '3'
provider:
name: aws
# https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
runtime: python3.9
region: eu-west-1
# https://www.serverless.com/framework/docs/providers/aws/guide/deploying#deployment-method
deploymentMethod: direct
stage: dev
profile: <aws profile name>
functions:
hello:
handler: handler.hello
plugins:
- serverless-better-credentials
- serverless-python-requirements
Full error
Environment: darwin, node 14.19.1, framework 3.23.0, plugin 6.2.2, SDK 4.3.2
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error: Cannot find module '@serverless/utils/log'
Require stack:
- /Users/user/Code/Projects/sls-project/node_modules/serverless-better-credentials/dist/ServerlessBetterCredentials.js
- /Users/user/Code/Projects/sls-project/node_modules/serverless-better-credentials/dist/index.js
- /Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/utils/import-module.js
- /Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/classes/plugin-manager.js
- /Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/serverless.js
- /Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/scripts/serverless.js
- /Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/bin/serverless.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (/Users/user/Code/Projects/sls-project/node_modules/serverless-better-credentials/dist/ServerlessBetterCredentials.js:6:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object.<anonymous> (/Users/user/Code/Projects/sls-project/node_modules/serverless-better-credentials/dist/index.js:8:55)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at module.exports (/Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/utils/import-module.js:5:12)
at PluginManager.requireServicePlugin (/Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/classes/plugin-manager.js:171:14)
at PluginManager.resolveServicePlugins (/Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/classes/plugin-manager.js:198:29)
at PluginManager.loadAllPlugins (/Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/classes/plugin-manager.js:136:47)
at Serverless.init (/Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/lib/serverless.js:141:30)
at async /Users/user/.nvm/versions/node/v14.19.1/lib/node_modules/serverless/scripts/serverless.js:591:7
```
Interesting -
I think this is because you're using a globally installed serverless, and the plugin is loading locally. I'll need to check to see how other plugins are working around this.
I think you can fix this immediately for yourself by running npm install --dev serverless
inside your working directory.
That does fix it for me. It prints Running "serverless" from node_modules
and works. Thank you.
Should I have package.json with serverless and this package in dev deps for other users of the project to set it up? I'm working on a python project and only have the serverless generated package-lock.json in my project.
Good to hear ๐
I would recommend (and I think most would too) that you use a locally (i.e. repo level) install of serverless with a checked in package.json
. That way anyone using your repo keeps their versions of serverless and any plugins in sync. Doing this will saving you from future local-version mismatch headaches when new features are added, and make it easier to reproduce your builds.
Nevertheless - people do install serverless globally, so I'll update the readme to cover that use case!
(I'm closing this now the documentation has been updated. All the best on your serverless journey!)