Cannot resolve "provider" from file variable
See original GitHub issueHey, I’m getting an error on my serverless.yml:
provider: ${file(../../commons/serverless/provider.js):default}
where provider.js is : {name: 'aws'}
it gets translated by sls print as:
provider:
name:
name: aws
package: ${file(../../commons/serverless/package.js):default}
Works perfect and it’s the same .js script…
Is this a bug?
Even if I do: provider: ${file(../../commons/serverless/package.js):default}
it gets printed as indented inside provider.name…
https://github.com/serverless/serverless/blob/master/lib/plugins/print/print.js#L50
// provider treatment and defaults
this.cache.serviceProvider = service.provider;
if (_.isString(this.cache.serviceProvider)) {
service.provider = { name: this.cache.serviceProvider };
}
service.provider = _.merge(
{
stage: 'dev',
region: 'us-east-1',
variableSyntax: '\\${([^{}]+?)}',
},
service.provider
);
This is definetly the issue! ${file(…)} is being treated as a string.
sls print
with:
serverless.cli.consoleLog('serverless.service.provider');
serverless.cli.consoleLog(serverless.service.provider);
in provider.js
gives:
serverless.service.provider
{
stage: 'dev',
variableSyntax: undefined,
name: '${file(../../commons/serverless/provider.js):default}',
versionFunctions: true,
remoteFunctionData: null
}
serverless.service.provider
{
stage: 'dev',
variableSyntax: '\\${([ ~:a-zA-Z0-9._@\'",\\-\\/\\(\\)*?]+?)}',
name: {
name: 'aws',
runtime: 'nodejs10.x',
stage: 'dev',
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Serverless Cannot resolve variable - Stack Overflow
I have tried using self and importing the file as custom but the error still. I have tried to use a Json with...
Read more >Common errors - FAQ - A progressive Node.js framework
"Cannot resolve dependency" error. The most common culprit of the error, is not having the <provider> in the module's providers array. Please make...
Read more >"Variables resolver deprecation: Cannot load file from outside ...
I currently have the following in my serverless.yml file which has been working just fine: custom: webpack: ${file(../../.
Read more >Trying to populate non string value into a string for variable
Trying to populate non string value into a string for variable ${opt:stage, self:provider.stage}. Please make sure the value of the property is a...
Read more >How to Fix Java “cannot be resolved to a variable” Error
To fix Java “cannot be resolved to a variable” error, you must declare the variable inside the scope where you will utilize it....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Bump! I am experiencing this problem as well - I am trying to find a way to omit role settings when deploying to localstack, but setting them when deploying to AWS. Building the provider block in a javascript file seemed like a good way to achieve this, but when I output a single object with something like
and add the line to my serverless.yml
when I run
npx sls print
the output isThis seems like a really simple bug to fix - it looks like it’s expecting the provider to only ever be a string for name. But then actually parses the object being returned correctly. This is blocking us at the moment and we could really do with a quick fix
To address the question about plugins (given I mentioned the use of localstack), I have removed all plugin configurations from my serverless.yml and I get exactly the same output
Duplicate of #7207