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.

Spread Operator bug?

See original GitHub issue

Bug. I’m requiring a file with the following statement (using require because I’ll be using both on node and browser):

const user = require('skeemas/complexUser');

The working complexUser:

const user = require('./user');
const individual = require('./individual');
const company = require('./company');
const credential = require('./credential');

const complexUser = {
    type: {
        type: 'text',
        values: ['individual', 'company'],
        predefined: 'individual',
    }
}

Object.assign(complexUser, user, individual, company, credential);

module.exports = complexUser;

The NOT working complexUser:

const user = require('./user');
const individual = require('./individual');
const company = require('./company');
const credential = require('./credential');

module.exports = {
    type: {
        type: 'text',
        values: ['individual', 'company'],
        predefined: 'individual',
    },
    ...user,
    ...individual,
    ...company,
    ...credential,
};

Error thrown by Webpack:

 ERROR in ./node_modules/skeemas/complexUser.js
    Module parse failed: /Users/damz/Desktop/repmemo/node_modules/skeemas/complexUser.js Unexpected token (12:4)
    You may need an appropriate loader to handle this file type.
    |         predefined: 'individual',
    |     },
    |     ...user,
    |     ...individual,
    |     ...company,
     @ ./models/user.js 1:13-43
     @ ./models/userPresenter.js
     @ ./apps/user/components/profileForm.js
     @ ./apps/user/router.js
     @ ./apps/user/index.js

Both babel and node do not complain if running the file directly (https://goo.gl/E3ZSEq).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:38 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
TrySoundcommented, Aug 20, 2017

As I said spread operator is stage-3. So you don’t have it in your config. Please, help yourself and use such plugins directly. stage presets are changed too often.

6reactions
alangpiercecommented, Feb 1, 2018

The webpack parser will need to be updated to handle the syntax as well, since it has special-case code for each node type. I recently wrote a (hacky) webpack plugin that patches the parser to handle the syntax, so the updated “walk” functions in the code are approximately what will need to be changed. But it should be an easy fix, I think.

https://github.com/alangpierce/sucrase/tree/master/integrations/webpack-object-rest-spread-plugin https://github.com/alangpierce/sucrase/blob/master/integrations/webpack-object-rest-spread-plugin/src/index.ts#L111

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spread Operator Bug or Did I Miss Something? - JavaScript
Hey, all! First post! Anyway, I am stuck on this particular problem. I feel like my answer is doing what is asked in...
Read more >
Spread Operator Bug #130266 - microsoft/vscode - GitHub
Spread Operator Bug #130266 ... It autocompletes with some random function or text when the spread operator is typed (...).
Read more >
Object spread operator throw error in microsoft edge
I try to use cdn.polyfill.io and https://babeljs.io/docs/en/babel-polyfill but no luck. What i can do to run my webpack code in microsoft edge?
Read more >
1644987 - Object spread syntax in console not working
Bugbug thinks this bug should belong to this component, but please revert this change in case of error. Component: Untriaged → Console.
Read more >
Spread operator shows syntax error with ECMA 6 and ...
The spread operator is valid syntactically. This code actually works even though it shows errors throughout the module and project. What happens instead?...
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