Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running webpack for local testing #6

Open
goldytech opened this issue Oct 12, 2017 · 3 comments
Open

Running webpack for local testing #6

goldytech opened this issue Oct 12, 2017 · 3 comments

Comments

@goldytech
Copy link

Hi,
I have created a local js file with its dependency getting import in the handler.js as below

import JsonValidator from './src/jsonvalidator'

Now when i run this on local for testing purpose using mock event json. I'm getting error import undrfined error

This is because i assume the code is not getting transpiled in local and only when it gets deployed.

So how do i transpile my code for local debugging and testing ?

@jayair
Copy link
Member

jayair commented Oct 12, 2017

@goldytech It does transpile on local. We cover this in the tutorial. In this chapter for example - https://serverless-stack.com/chapters/add-a-get-note-api.html. When we run the serverless invoke local --function get --path mocks/get-event.json, it transpiles the given function handler.

@goldytech
Copy link
Author

I've pushed my code on Github https://github.com/goldytech/aws-serverless
When i run the command serverless invoke local --function hello --path mocks/data-event.json

I get this error

/home/dave/lf-bi-api/handler.js:2
import JsonValidator from './src/jsonvalidator'
^^^^^^
SyntaxError: Unexpected token import
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at AwsInvokeLocal.invokeLocalNodeJs (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:251:33)
    at AwsInvokeLocal.invokeLocal (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:125:19)
    at AwsInvokeLocal.tryCatcher (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/dave/.nvm/versions/node/v6.10.3/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

@jayair
Copy link
Member

jayair commented Oct 13, 2017

@goldytech I tried your repo. YAML is really strict, this line https://github.com/goldytech/aws-serverless/blob/master/serverless.yml#L21 should be - serverless-webpack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants