Skip to content
New issue

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

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

Already on GitHub? # to your account

babel example does not work - syntax error on 'export' #290

Closed
felzix opened this issue Nov 30, 2017 · 8 comments
Closed

babel example does not work - syntax error on 'export' #290

felzix opened this issue Nov 30, 2017 · 8 comments

Comments

@felzix
Copy link

felzix commented Nov 30, 2017

This is a Bug Report

Description

I copied the files in the babel example* into a new project, deployed to AWS, then tested the function in the lambda page on AWS. I got a syntax error:

START RequestId: e96ff5ae-d617-11e7-a383-e943fb5623d8 Version: $LATEST
Syntax error in module 'handler': SyntaxError
export const hello = (event, context, cb) => {
^^^^^^
SyntaxError: Unexpected token export
    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)
END RequestId: e96ff5ae-d617-11e7-a383-e943fb5623d8
REPORT RequestId: e96ff5ae-d617-11e7-a383-e943fb5623d8	Duration: 5.31 ms	Billed Duration: 100 ms 	Memory Size: 1024 MB	Max Memory Used: 20 MB	

My project, minus node_modules and .serverless: backend.zip

* https://github.com/serverless-heaven/serverless-webpack/tree/master/examples/babel

Additional Data

  • Serverless-Webpack Version you're using: 4.1.0
  • Webpack version you're using: 3.9.1
  • Operating System: iOS
@HyperBrain
Copy link
Member

Hi @felzix , thanks for reporting.

Did you also try the babel-dynamically-entries example?

I will check the files you provided and try to find out what's wrong.

@Vadorequest
Copy link

I also have an issue with the babel example, but I get a different error (I'm not running the example itself) but my own, based on the same webpack.config.js

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.entry should be one of these:
   object { <key>: non-empty string | [non-empty string] } | non-empty string | [non-empty string] | function
   The entry point(s) of the compilation.
   Details:
    * configuration.entry should NOT have less than 1 properties ({
        "keyword": "minProperties",
        "dataPath": ".entry",
        "schemaPath": "#/oneOf/0/minProperties",
        "params": {
          "limit": 1
        },
        "message": "should NOT have less than 1 properties",
        "schema": 1,
        "parentSchema": {
          "minProperties": 1,
          "additionalProperties": {
            "oneOf": [
              {
                "description": "The string is resolved to a module which is loaded upon startup.",
                "minLength": 1,
                "type": "string"
              },
              {
                "description": "All modules are loaded upon startup. The last one is exported.",
                "$ref": "#/definitions/common.nonEmptyArrayOfUniqueStringValues"
              }
            ]
          },
          "description": "Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.",
          "type": "object"
        },
        "data": {}
      }).
      object { <key>: non-empty string | [non-empty string] }
      Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.
    * configuration.entry should be a string.
    * configuration.entry should be an array:
      [non-empty string]
    * configuration.entry should be an instance of function
      function returning an entry object or a promise..
    at webpack (/Users/vadorequest/dev/student-loan-simulator-serverless/simulator-feedback/node_modules/webpack/lib/webpack.js:19:9)
    at ServerlessWebpack.compile (/Users/vadorequest/dev/student-loan-simulator-serverless/simulator-feedback/node_modules/serverless-webpack/lib/compile.js:11:22)
From previous event:
    at PluginManager.invoke (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/PluginManager.js:372:22)
    at PluginManager.spawn (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/PluginManager.js:390:17)
    at ServerlessWebpack.BbPromise.bind.then.then (/Users/vadorequest/dev/student-loan-simulator-serverless/simulator-feedback/node_modules/serverless-webpack/index.js:110:51)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.9.4
     Serverless Version:     1.26.0

webpack config:

const path = require('path');
const slsw = require('serverless-webpack');

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'babel-loader'
          }
        ],
      }
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  }
};

I used the same package version in case of, but... :/

@HyperBrain
Copy link
Member

@Vadorequest This looks more like a misconfiguration of the function handlers in the serverless.yml.

If your functions are located in subdirectories, the handler properties should contain the relative path to the handlers but without a preceding ./

@karlhorky
Copy link

karlhorky commented Feb 16, 2018

Edit Not sure if this is still necessary - I had to add this because I needed custom babel plugins that preset-env wasn't providing.


Are all of you using a .babelrc file with the following contents?

{
  "presets": [
    [
      "env",
      {
        "targets": {
          "node": "6.10"
        }
      }
    ]
  ]
}

Stole / adapted that from here: https://github.com/serverless/serverless-graphql/blob/c78c5f9840d76e9534ea1f15595683e844d2171d/app-backend/appsync/lambda/.babelrc

@HyperBrain
Copy link
Member

@karlhorky Sorry, no. We use the "node6" babel preset in our .babelrc like this:

{
  "comments": false,
  "presets": [ "node6", "stage-0" ],
  "plugins": [
    "transform-decorators-legacy"
  ],
  "env": {
    "development": {
      "plugins": [
        "source-map-support"
      ]
    },
    "production": {
      "plugins": [
        "source-map-support"
      ]
    },
    "cli": {
      "plugins": [
      ]
    },
    "test": {
      "plugins": [
      ]
    }
  }
}

To dynamically enable different plugin sets depending on the environment.

@HyperBrain
Copy link
Member

@felzix The old (deprecated) babel example has been removed and is replaced by the dynamic example now. Does that work for you?

@HyperBrain
Copy link
Member

Any update here? If not I'll close the issue soon.

@HyperBrain
Copy link
Member

Closing now. Feel free to continue the discussion if needed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants