matthewp / robot

🤖 A functional, immutable Finite State Machine library
https://thisrobot.life
BSD 2-Clause "Simplified" License
1.92k stars 88 forks source link

TypeError: Cannot read properties of undefined (reading 'default') #198

Closed multivac61 closed 1 year ago

multivac61 commented 1 year ago

Writing down the issue described in this Twitter thread.

When using the newest version of robot in a SvelteKit project I get the following errors.

10:09:54 AM [vite] page reload src/routes/+page.svelte
TypeError: Cannot read properties of undefined (reading 'default')
    at +page.svelte:4:73
    at Object.$$render (/node_modules/.pnpm/svelte@3.55.1/node_modules/svelte/internal/index.mjs:1892:22)
    at Object.default (root.svelte:42:40)
    at eval (/node_modules/.pnpm/@sveltejs+kit@1.10.0_svelte@3.55.1+vite@4.1.4/node_modules/@sveltejs/kit/src/runtime/components/layout.svelte:8:41)
    at Object.$$render (/node_modules/.pnpm/svelte@3.55.1/node_modules/svelte/internal/index.mjs:1892:22)
    at root.svelte:41:39
    at $$render (/node_modules/.pnpm/svelte@3.55.1/node_modules/svelte/internal/index.mjs:1892:22)
    at Object.render (/node_modules/.pnpm/svelte@3.55.1/node_modules/svelte/internal/index.mjs:1900:26)
    at Module.render_response (/node_modules/.pnpm/@sveltejs+kit@1.10.0_svelte@3.55.1+vite@4.1.4/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:180:29)
    at async Module.render_page (/node_modules/.pnpm/@sveltejs+kit@1.10.0_svelte@3.55.1+vite@4.1.4/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:310:10)

Here is a GitHub repo containing the code.

npx envinfo --system --npmPackages svelte,rollup,webpack,robot3,svelte-robot-factory --binaries --browsers

  System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.57 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.3.0 - ~/.nvm/versions/node/v19.3.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.2.0 - ~/.nvm/versions/node/v19.3.0/bin/npm
  Browsers:
    Chrome: 110.0.5481.100
    Firefox: 110.0.1
    Safari: 16.3
  npmPackages:
    robot3: ^0.4.0 => 0.4.0
    svelte: ^3.54.0 => 3.55.1

SvelteKit issues when importing

Importing import { createMachine, invoke, reduce, state, interpret, transition } from 'robot3' causes an internal error in SvelteKit (see REPL).

Treating robot as a module with a default export, it works (see REPL):

import robot from 'robot3'
const { createMachine, invoke, reduce, state, interpret, transition } = robot;
juho commented 1 year ago

Encountering the same issue. Downgraded to 0.3.1 for the time being.

matthewp commented 1 year ago

I believe this is only a problem in their repl and it's something they are fixing (have already fixed?)

erikrahm commented 1 year ago

@matthewp this is still a problem, but one with an easy solution! Just put up a PR for it here: https://github.com/matthewp/robot/pull/202 (cc. @multivac61 @juho)

matthewp commented 1 year ago

Fixed by #202, thanks @erikrahm !