question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot resolve "provider" from file variable

See original GitHub issue

Hey, 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:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
beldougiecommented, Apr 29, 2020

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

{
  name: 'aws',
  runtime: 'nodejs12.x',
  stage: '${opt:stage, 'dev}'
  // ... etc
}

and add the line to my serverless.yml

provider: ${file(./config/${opt:stage}.provider.js)}

when I run npx sls print the output is

provider:
  name:
    name: 'aws'
    runtime: 'nodejs12.x'
    stage: 'dev'

This 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

0reactions
medikoocommented, Apr 30, 2020

Duplicate of #7207

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found