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

Spread operator failing after babel update #798

Closed
HRK44 opened this issue Jul 9, 2019 · 8 comments
Closed

Spread operator failing after babel update #798

HRK44 opened this issue Jul 9, 2019 · 8 comments

Comments

@HRK44
Copy link

HRK44 commented Jul 9, 2019

I'm submitting a bug report

Webpack Version:
3.8.1

Babel Core Version:
7.5.0

Babel Loader Version:
8.0.6

Please tell us about your environment:
Linux

Current behavior:

ERROR in ./src/utils/logger/logger.js
Module parse failed: Unexpected token (50:10)
You may need an appropriate loader to handle this file type.
|           filename: 'logs/infos.%DATE%.log',
|           level: process.env.LOG_LEVEL || 'info',
|           ...config
|         }), new _winstonDailyRotateFile.default({
|           name: 'error-file',
 @ ./src/app.js 9:37-69
 @ multi ./src/app.js

Expected/desired behavior:

Should work fine since spread operator is already handled by nodejs

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration.

This is related to this issue : https://stackoverflow.com/questions/56900902/babel-with-nodejs-not-working-spread-operator

package.json:

"devDependencies": {
        "@babel/cli": "7.5.0",
        "@babel/core": "7.5.0",
        "@babel/node": "7.5.0",
        "@babel/plugin-proposal-class-properties": "7.5.0",
        "@babel/plugin-transform-runtime": "7.5.0",
        "@babel/preset-env": "7.5.2",
        "babel-eslint": "10.0.2",
        "babel-loader": "8.0.6",
        "eslint": "6.0.1",
        "nodemon": "1.19.1",
        "webpack": "3.8.1",
        "webpack-node-externals": "1.7.2"
    },
    "dependencies": {
        "@babel/runtime": "7.5.2",
        "winston": "3.2.1",
        "winston-daily-rotate-file": "3.9.0"
    }

.babelrc:

{
    "plugins": [
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-transform-runtime"
    ],
    "presets": [
        [
            "@babel/preset-env",
            {
                "modules": "commonjs",
                "targets": {
                    "node": "current"
                },
                "useBuiltIns": "usage",
                "corejs": { "version": 3, "proposals": true }
            }
        ]
    ]
}

webpack.config.js:

'use strict';

const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');

/*-----------------------------
Server Config
-----------------------------*/
module.exports = {
    name: 'server',
    target: 'node',
    externals: [nodeExternals({
        modulesDir: path.join(__dirname, '/node_modules')
    })],
    context: __dirname,

    entry:  [
        path.join(__dirname, 'src/app.js')
    ],

    output: {
        path: path.join(__dirname, '/build'),
        filename: 'server.js',
        libraryTarget: 'commonjs2'
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: [
                    path.join(__dirname, '/node_modules'),
                ],
                use: [
                    {
                        loader: 'babel-loader'
                    }
                ]
            }
        ]
    },

    plugins: [
        new webpack.optimize.AggressiveMergingPlugin()
    ],

    devtool: 'cheap-eval-source-map',

    resolve: {
        extensions: ['.js'],
        modules: ['node_modules']
    }
};
  • What is the expected behavior?

I'm just using NodeJS v10+, only using babel for the import/export es6 module syntax for node. Spread operator should be handled by node js so I don't want babel to do anything about that.

@HRK44 HRK44 changed the title Spread operator failing after Spread operator failing after babel update Jul 9, 2019
@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Jul 9, 2019

Spread operator should be handled by node js so I don't want babel to do anything about that.

Yeah exactly, Babel isn't doing anything. That problem error is thrown by an old webpack version which doesn't understand object spread.
You can either update webpack, or transpile object spread.

@HRK44
Copy link
Author

HRK44 commented Jul 9, 2019

@nicolo-ribaudo I'm confused as why it was working before with the same webpack version, and stopped working once I updated the babel packages ?

@nicolo-ribaudo
Copy link
Member

Do you havea yarn.lock/package-lock.json file?

@HRK44
Copy link
Author

HRK44 commented Jul 9, 2019

Yes I'm using npm and I have package-lock.json, I have updated webpack to 4.x and it seems to work correctly now.

@nicolo-ribaudo
Copy link
Member

Which was the previous Babel version? If you had a lockfile updating Babel shouldn't cause anu change in acorn (the parser used by webpack) 🤔

@HRK44
Copy link
Author

HRK44 commented Jul 12, 2019

Sorry for the delayed answer.

This is my package.json changelog when it was working to when it was not working :

     "devDependencies": {
-        "@babel/cli": "7.2.3",
-        "@babel/core": "7.2.2",
-        "@babel/node": "7.2.2",
-        "@babel/plugin-proposal-class-properties": "7.3.0",
-        "@babel/plugin-transform-runtime": "7.2.0",
-        "@babel/preset-env": "7.3.1",
-        "babel-loader": "8.0.5",
-        "webpack": "3.8.1",
+        "@babel/cli": "7.5.0",
+        "@babel/core": "7.5.0",
+        "@babel/node": "7.5.0",
+        "@babel/plugin-proposal-class-properties": "7.5.0",
+        "@babel/plugin-transform-runtime": "7.5.0",
+        "@babel/preset-env": "7.5.2",
+        "babel-loader": "8.0.6",
         "webpack": "3.8.1",
         "webpack-node-externals": "1.7.2"
     },
     "dependencies": {
-        "@babel/runtime": "7.3.1",
+        "@babel/runtime": "7.5.2",
     }

@HRK44
Copy link
Author

HRK44 commented Jul 12, 2019

And this is working :

    "devDependencies": {
        "@babel/cli": "7.5.0",
        "@babel/core": "7.5.0",
        "@babel/node": "7.5.0",
        "@babel/plugin-proposal-class-properties": "7.5.0",
        "@babel/plugin-transform-runtime": "7.5.0",
        "@babel/preset-env": "7.5.2",
        "babel-loader": "8.0.6",
        "webpack": "4.35.3",
        "webpack-cli": "^3.3.5",
        "webpack-node-externals": "1.7.2"
    },
    "dependencies": {
        "@babel/runtime": "7.5.2",
    }

@JLHwung
Copy link
Contributor

JLHwung commented Sep 30, 2019

You can check the acorn (Parser used by Webpack) version by

npx nls why acorn

Make sure it is higher than 5.4.0, the first version with object spread support.

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

3 participants