Serverless-webpack: Bug Report. Node.js 8.10. Building for Production. serverless-webpack 5.1.1.

Created on 5 Apr 2018  Â·  17Comments  Â·  Source: serverless-heaven/serverless-webpack

Bug Report

Description

  • What went wrong?

    • Migration from 6.10 to 8.10
  • What was the config you used?

    • Changed targets in .babelrc from 6.10 to 8.10
    • Changed runtime in serverless.yml from 6.10 to runtime: nodejs8.10
  • What stacktrace or error message from your provider did you see?

    • It doesn't give any meaningful error, I even removed uglify from the webpack config, but still receive without produced file:
ERROR in Unexpected token (1106:32)

Additional Data

  • Serverless-Webpack Version you're using: 5.1.1
  • Webpack version you're using: 4.4.1
  • Serverless Framework Version you're using: 1.26.1
  • Operating System: MacOS High Sierra 10.13.3

.babelrc:

{
  "presets": [
    ["env", {
      "targets": {
        "node": "8.10"
      }
    }]
  ],
  "plugins": [
    "syntax-dynamic-import", // tried with and without
    "transform-es2015-template-literals", // tried with and without
    "transform-object-rest-spread", // tried with and without
    "syntax-object-rest-spread", // tried with and without
    ["transform-imports", {
      "my-library": {
        "transform": "../../path/to/transform.js",
        "preventFullImport": true
      }
    }],
    ["babel-plugin-inline-import", {
      "extensions": [".gql"]
    }]
  ]
}

Most helpful comment

You need to use the babel-preset-stage-2 preset together with the env preset when using 8.10 as target.

The problem is, that the pure env 8.10 preset does not include the spread rest operator and import.
So use

"presets": [
    ["env", {
      "targets": {
        "node": "8.10"
      }
    }],
    "stage-2"
  ],

We did the transistion yesterday for our projects and that way it works.

All 17 comments

Also tried node versions:
8.9.4 - 8.6.0 - 8.2.1 - 7.10.1 - 7.5.0
From http://node.green/
Building for all of these also produces the same error as above.

You need to use the babel-preset-stage-2 preset together with the env preset when using 8.10 as target.

The problem is, that the pure env 8.10 preset does not include the spread rest operator and import.
So use

"presets": [
    ["env", {
      "targets": {
        "node": "8.10"
      }
    }],
    "stage-2"
  ],

We did the transistion yesterday for our projects and that way it works.

@HyperBrain Life saver! Just checked it and it worked! Thank You!
Allow me to improve your kindly provided solution, others, be aware that it's stage-2 (DASH), not stage2.
So run install:

npm i -D babel-preset-stage-2

And then add:

  "presets": [
    ["env", {
      "targets": {
        "node": "8.10"
      }
    }],
    "stage-2"  // <------ dash here as well
  ],

@OlzhasAlexandrov I updated my comment to include the dash (wrote the answer just too quickly 😄 ). Thanks for the correction.

stage-2 includes a lot of things that most code won't need. For Object Rest/Spread Properties, since this is a stage 4 proposal (has been shipped in browsers) babel-preset-env starting with v2 (and also the v7+ @babel/preset-env) has a shippedProposals option that enables transpilation of stage 4 proposals.

So you can avoid installing the stage-2 preset and just configure preset-env:

"presets": [
  [
    "env",
    {
      "targets": {
        "node": "8.10"
      },
      "shippedProposals": true
    }
  ]
]

My full config for anyone interested, based on the Babel 7 beta packages:

// .babelrc.js
module.exports = {
  comments: false,
  presets: [
    [
      // Use the `@babel/preset-env` package at version 7.0.0-beta.44
      '@babel/env',
      {
        targets: {
          node: '8.10',
        },
        shippedProposals: true,
        // Polyfill less
        useBuiltIns: 'usage',
      },
    ],
  ],
  plugins: [
    // For Flow types
    '@babel/transform-flow-strip-types',
    // For a better way of polyfilling of things that aren't transpiled
    [
      '@babel/transform-runtime',
      {
        polyfill: false,
        regenerator: false,
      },
    ],
  ],
};

Packages in package.json (note the beta babel-loader too):

  "devDependencies": {
    "@babel/core": "^7.0.0-beta.44",
    "@babel/plugin-transform-flow-strip-types": "^7.0.0-beta.44",
    "@babel/plugin-transform-runtime": "^7.0.0-beta.44",
    "@babel/preset-env": "^7.0.0-beta.44",
    "babel-loader": "^8.0.0-beta.2",
    "serverless-webpack": "^5.1.1",
    "webpack": "^4.5.0",
    "webpack-node-externals": "^1.7.2"
  },
  "dependencies": {
    "@babel/runtime": "^7.0.0-beta.44"
  },

@karlhorky
Doesn't work with the exact same configuration as yours and same packages.

ERROR in unknown: Unexpected token (374:15)

ERROR in Unexpected token (374:15)

  Error --------------------------------------------------

  Webpack compilation error, see above

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

I did, however, improve the original proposal of @HyperBrain a bit:

{
  "presets": [ ["env", { "modules": false, "targets": { "node": "8.10" } }] ],
  "plugins": [
    // following 2 plugins were unnecessary from stage-2 (that includes stage-3 plugins)
    // "transform-class-properties",
    // "transform-async-generator-functions",
    "transform-object-rest-spread",
    "syntax-trailing-function-commas",
    "transform-async-to-generator",
    "transform-exponentiation-operator",
  ]
}

@OlzhasAlexandrov which version of babel-preset-env do you have? You need at least 2+. I did update the packages in the last few minutes again.

There are also newer versions of serverless-webpack and webpack itself.

@karlhorky
I was trying to use the exact same config and package versions as yours, it started to successfully build with:

module.exports = {
  comments: false,
  presets: [
    [
      "@babel/env",
      {
        targets: {
          node: "8.10",
        },
        shippedProposals: true,
        // Polyfill less
        useBuiltIns: "usage",
      },
    ],
  ],
  plugins: [
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/transform-async-to-generator",
    "@babel/transform-exponentiation-operator",
    // For a better way of polyfilling of things that aren't transpiled
    [
      "@babel/transform-runtime",
      {
        polyfill: false,
        regenerator: false,
      },
    ],
  ],
}

UPDATE: was able to get rid of one more plugin. I was simply toggling them and rebuilding.

Hm, not sure what the problem is, but those first two plugins shouldn't be required. The third one (exponentiation operator) however will be, since it's still Stage 3 as of now: https://github.com/rwaldron/exponentiation-operator/blob/966cc6ec7f2009e6a8e2d15de8baf60318cadd6b/readme.md

@karlhorky i have an issue #448 related to babel7 upgrade. Could you take a look please if you have time?

If anyone can help me out I am getting this error for this issue:

ERROR in ./getCaseRecord.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-preset-stage-3/lib/index.js
    at createDescriptor (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at items.map (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:120:22)
    at loadPrivatePartialConfig (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/partial.js:85:55)
    at Object.loadPartialConfig (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/partial.js:110:18)
    at Object.<anonymous> (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:144:26)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:3:103)
    at _next (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:194)
    at /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:364
    at new Promise (<anonymous>)
    at Object.<anonymous> (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:97)
    at Object._loader (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:224:18)
    at Object.loader (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:60:18)
    at Object.<anonymous> (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:55:12)

here is what is in my .babelrc file:

{
    "plugins": [],
    "presets": [
        ["env", {"node": "10.14.1"}],
        "stage-3"
    ]
}

Here are my dependencies in my package.json:

"devDependencies": {
    "aws-sdk": "^2.350.0",
    "babel-core": "^6.26.3",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.6",
    "babel-plugin-source-map-support": "^2.0.1",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-3": "^6.24.1",
    "eslint": "^5.15.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-node": "^9.1.0",
    "eslint-plugin-promise": "^4.0.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-standard": "^4.0.0",
    "jest": "^24.8.0",
    "serverless-offline": "^5.0.0",
    "serverless-webpack": "^5.1.0",
    "webpack": "^4.16.2",
    "webpack-node-externals": "^1.6.0"
  },

What do you think? Should I just go back to 7 and be done with this??? I really want to stay current and use the most recent version of babel if at all possible.

thanks and lmk!

Did you already try to use babel v7 ?

  ...
    "@babel/core": "^7.3.4",
    "@babel/preset-env": "^7.3.4",
    "@babel/preset-stage3": "^7.0.0",
   ...

(The version numbers are examples only. Please check for the latest ones)

And please provide the Webpack and plugin versions you use.

On Wed, Jun 5, 2019 at 11:35 PM David Lopez notifications@github.com
wrote:

If anyone can help me out I am getting this error for this issue:

RROR in ./getCaseRecord.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-preset-stage-3/lib/index.js
at createDescriptor (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
at items.map (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
at Array.map ()
at createDescriptors (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
at createPresetDescriptors (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
at presets (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
at mergeChainOpts (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:320:26)
at /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:283:7
at buildRootChain (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/config-chain.js:120:22)
at loadPrivatePartialConfig (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/partial.js:85:55)
at Object.loadPartialConfig (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/@babel/core/lib/config/partial.js:110:18)
at Object. (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:144:26)
at Generator.next ()
at asyncGeneratorStep (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:3:103)
at _next (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:194)
at /Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:364
at new Promise ()
at Object. (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:5:97)
at Object._loader (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:224:18)
at Object.loader (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:60:18)
at Object. (/Users/MyDocs/DevOps/QuickAutoTags/services/v2.crm-case-record-api/node_modules/babel-loader/lib/index.js:55:12)

here is what is in my .babelrc file:

{
"plugins": [],
"presets": [
["env", {"node": "10.14.1"}],
"stage-3"
]
}

Here are my dependencies in my package.json:

"devDependencies": {
"aws-sdk": "^2.350.0",
"babel-core": "^6.26.3",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.6",
"babel-plugin-source-map-support": "^2.0.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-3": "^6.24.1",
"eslint": "^5.15.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.8.0",
"serverless-offline": "^5.0.0",
"serverless-webpack": "^5.1.0",
"webpack": "^4.16.2",
"webpack-node-externals": "^1.6.0"
},

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/serverless-heaven/serverless-webpack/issues/363?email_source=notifications&email_token=ABKEZXU2TWIZK3ORMKU2JIDPZAWRZA5CNFSM4EY7MY22YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXBCXLY#issuecomment-499264431,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABKEZXW7BRSPOCAASTNSILTPZAWRZANCNFSM4EY7MY2Q
.

@HyperBrain Thanks!

Im using WebPack4 and Yes in another build I have used Babel v7 successfully. I am upgrading my dependencies and moved up to 8 while using it with the serverless-webpack-plugin v5

I left you a copy of all of my dependencies with versions so you can see. I am assuming that serverless-webpack does not support babel v8 in this case eh?

What do you think?

serverless-webpack does not support babel v8 in this case eh?

Hmmm, might be possible. @serverless-heaven/serverless-webpack-team did anyone already test successfully with babel v8? If not this would make up a good addition for one of the next releases.

serverless-webpack does not support babel v8 in this case eh?

Hmmm, might be possible. @serverless-heaven/serverless-webpack-team did anyone already test successfully with babel v8? If not this would make up a good addition for one of the next releases.

Just in case it helps, the only way I could get it to work was to comment out babel-loader as such:

module: {
    rules: [
      {
        test: /\.js$/,
        // TODO: This was the fix to sls deploy
        // loader: "babel-loader",
        include: __dirname,
        exclude: /node_modules/
      }
    ]
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

heri16 picture heri16  Â·  4Comments

jaydp17 picture jaydp17  Â·  4Comments

bitttttten picture bitttttten  Â·  4Comments

jmparsons picture jmparsons  Â·  5Comments

wooooooak picture wooooooak  Â·  5Comments