mattpocock / xstate-codegen

A codegen tool for 100% TS type-safety in XState
MIT License
245 stars 12 forks source link

UnhandledPromiseRejectionWarning: Error: You have declared using "bundled" babelHelpers #43

Open ivandotv opened 3 years ago

ivandotv commented 3 years ago

I'm using nextjs framework, and this is the error that I get when trying to generate the code.

UnhandledPromiseRejectionWarning: Error: You have declared using "bundled" babelHelpers, but transforming /home/user/path.to.machine/file.ts resulted in "runtime". Please check your configuration.

packages: xstate-codegen@0.1.3 next@9.5.3 xstate@4.13.0

mattpocock commented 3 years ago

Thanks for this @ivandotv

This is another error caused by bundling, that will be fixed when we move to a TS-only extraction process in this PR: #29

That PR is our top priority right now - we're testing it this week.

See comments in other issues: #21 and #23.

But let's try to find a workaround. Do you have a babel.config.js knocking about?

ivandotv commented 3 years ago

Actually I do ( I should have mentioned that earlier)

const pkg = require('./package.json')
const childProcess = require('child_process')
const pkgVersion = `${
  process.env.PKG_VERSION || pkg.version
}-${childProcess.execSync('git rev-parse --short HEAD')}`

module.exports = {
  presets: ['next/babel'],
  plugins: [
    ['inline-react-svg'],
    [
      'transform-define',
      {
        __VERSION__: pkgVersion,
        __DEV__: process.env.NODE_ENV !== 'production'
      }
    ]
  ]
}

This is on top of nextjs babel config. https://nextjs.org/docs/advanced-features/customizing-babel-config

mattpocock commented 3 years ago

Our current rollup-based machine extractor sometimes reads from babel.config.js, so playing with commenting out things in your config may yield some results. Obviously, that may not be a sufficient workaround.

If you can't find a workaround here, it might be worth waiting until #29 is in. We'll be releasing it on a @next branch and I'll make sure to notify you.

ivandotv commented 3 years ago

I can't mess around with the next/babel preset. I will wait for the @next release. Using Typescript with xstate is such a pain. Thank you for a prompt reply.

borispinus commented 3 years ago

in my case the problem was conflict between @babel/transform-runtime(in my project) and @rollup/plugin-babel(in xstate-codegen)

i'm using webpack for app bundling, so the solution was not to use @babel/transform-runtime during xstate-codegen processing

in my .babelrc.js

if (process.title === "webpack") {
  plugins.push("@babel/transform-runtime");
}