carloslfu / xstate-router

XState Router. Add routes to your XState machine.
MIT License
112 stars 16 forks source link

Failed to compile due to object rest spread #10

Closed ishabo closed 4 years ago

ishabo commented 4 years ago

Hi @carloslfu. Thank you very much for this useful library.

I tried to make it work in my react-app/typescript project but I am getting the following error when I build my project with your lib:

./node_modules/xstate-router/lib/index.js
Module parse failed: Unexpected token (68:21)
You may need an appropriate loader to handle this file type.
| exports.getRoutes = getRoutes;
| function addRouterEvents(history, configObj, routes) {
|     const config = { ...configObj };
|     if (!config.on) {
|         config.on = {};

This is due to the "target" set in your tsconfig. I forked your project and changed

    "target": "es2018",

to

    "target": "es2016",

This causes the JS build to change from

    const config = { ...configObj };

to

    const config = Object.assign({}, configObj);

After making this change in my fork, my project builds with your lib without issues.

ishabo commented 4 years ago

Please accept my PR if you agree with the change: https://github.com/carloslfu/xstate-router/pull/11/files