diegomura/react-pdf

Can't build with dfa 1.2.0

Closed this issue Β· 7 comments

Describe the bug
I have a rails project with react, using webpacker and mostly babel for transforming javascript. When I try to use the @react-pdf/renderer in the project, the compiling of webpacker fails. I get the following error:

ERROR in ./node_modules/@react-pdf/fontkit/dist/fontkit.browser.es.js 8713:23-35 "export 'default' (imported as 'StateMachine') was not found in 'dfa'

To Reproduce
0. Setup a Ruby on Rails project with react, i.e. with react-rails

  1. yarn install @react-pdf/renderer
  2. import { Page, Text, View, Document, StyleSheet } from '@react-pdf/renderer' in React-Component
  3. Compile the project with webpacker or ./bin/webpack-dev-server

Indeed, if I look in the file /node_modules/@react-pdf/fontkit/dist/fontkit.browser.es.js line 6, where it tries to load the StateMachine it really looks like a bug to me.

import StateMachine from 'dfa'

And then in ./node_modules/dfa/index.js
The last line: module.exports = StateMachine is trying to export as commonJS and not as es-format.

Am I overseeing something here? Or is this actually a bug? I currently try to do some babel or webpack-config to solve this problem, but it seems like an issue to me.

Expected behavior
Make this instantly work, without the need to do additional webpack or babel config.

Desktop (please complete the following information):

  • React-pdf version [e.g. v1.1.0]
  • @react-pdf/fontkit version 1.13.0

After some deeper research I currently have the feeling, that this comes back to an issue with dfa 1.2.0 (that was published yesterday!). https://www.npmjs.com/package/dfa

When I install the version 1.1.0 I get a precompliled version, that is understood by fontkit. The index.js at the 1.2.0 seems to be not precompiled, causing issues at importing it property at fontkit.

Thanks! We can clse it then since it’s not a react-pdf bug?

Hm, it actually has an impact on installing react-pdf currently (fails to install), if my suspicion is correct. But yeah, I should try to adress this at dfa.

I solved it adding the resolutions section in package.json

"dfa": "1.1.0"

And of course the package with that version as well

I get the error like this:
ERROR in 113e60489ac1aee4007d.bundle.js from UglifyJs
Unexpected token: name (StateMachine)

solved use dfa verison 1.1.0 in @react-pdf/fontkit

I just had this same problem and the fix from @cristofer worked pretty well.

It looks like there is a potential fix for the downstream issue here foliojs/dfa#4