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.

1.18.0 breaks referencing variables in Javascript Files

See original GitHub issue

This is a Bug Report

Description

This might be considered an edge case based upon how I make use of a JavaScript configuration file but thought I would share this issue nonetheless as it tripped me up when I went to do a deploy this evening after updating my deps.

Consider the following contrived example.

config.js

const env    = process.env.NODE_ENV || 'dev';
const config = { destinationStream : `kinesis-stream-${env}` }

config._get = function () { return this; }
module.exports = config;

serverless.yml

custom :
    destinationStream : ${file(./config.js):_get.destinationStream}

cmd to reproduce

> NODE_ENV=staging serverless package

Running the above cmd results in the following error.

Invalid variable syntax when referencing file "./config.js". Check if your javascript is returning the correct data.

Note this issue did not exist prior to 1.18.

I’ve reviewed the PR’s which made up 1.18 and have pin-pointed #3888 as being the change which introduced this new behaviour.

Prior to 1.18 when a JS file was resolved it was immediately invoked and so it’s context was maintained. However in #3888 it is assigned to a local variable and so no-longer has it’s original execution context. ( see lib/classes/Variables#L255 )

This can be fixed by amending L255 to :

valueToPopulate = returnValueFunction.call(jsFile);

I’d be happy to submit a PR for this if you think it’s worth fixing. I’ve since worked around it but as per above I thought I’d share the info.

Additional Data

  • Serverless Framework Version you’re using: 1.18
  • Operating System: 10.12.5
  • Stack Trace: N/A
  • Provider Error messages: N/A

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pmuenscommented, Jul 26, 2017

Thanks for getting back @indieisaconcept and thanks for working on and submitting the PR 👍 🎉

We’ll review it ASAP so that the fix lands in master soon!

0reactions
pmuenscommented, Jul 27, 2017

@pmuens Tried it with the recent master commit d2e1ef8 but no success. I guess it isn’t related to this issue.

Thanks of trying it out @maikokuppe 👍

I’m going to open a seperate issue if it doesn’t resolve in the near future (some other 1.18.0 issues are currently being worked on).

That sounds like a good idea. We’ll release a patch release soon (1.18.1) and 1.19.0 will be released next week. Maybe you can try those versions and open up a new issue if the problem still persists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global variables in Javascript across multiple files
The variable can be declared in the .js file and simply referenced in the HTML file. My version of helpers.js : var myFunctionWasCalled...
Read more >
The 10 Most Common JavaScript Issues Developers Face
If you need help figuring out why your JavaScript isn't working, consult this list of the 10 most common JavaScript issues from a...
Read more >
The Go Programming Language Specification
Introduction. This is the reference manual for the Go programming language. The pre-Go1.18 version, without generics, can be found here.
Read more >
Introducing NGINX 1.18 and 1.19
We announce the latest branches of NGINX Open Source, the stable 1.18 branch and the mainline 1.19 branch. New to the stable branch...
Read more >
Changelog - Cypress Documentation
Cleaned up temp files generated by cypress run . ... Breaking Changes: ... Installing Cypress on your system now requires Node.js 14, 16...
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