Docz: Issue with tpl.js files that are copied over, running through prettier and failing on Heroku

Created on 9 Oct 2018  ·  13Comments  ·  Source: doczjs/docz

Bug Report

Describe the bug

npx docz build fails on heroku, it works perfectly on our OSX machines.

It looks to me like the template files that are generated are breaking as they're generated:

import React from 'react'
import { hot } from 'react-hot-loader'
import Theme from 'docz-theme-default'
import { imports } from './imports' import db from './db.json' 
const Root = () => (
  <theme db="{db}" imports="{imports}" hashrouter="{" false }   >
)
export default hot(module)(Root)

Once the broken files are copied over, prettier is failing to parse them.

screen shot 2018-10-09 at 15 10 28

✖  fatal     SyntaxError: Unexpected token, expected ";" (1:27)
> 1 | import React from 'react' import { hot } from 'react-hot-loader' import Theme from 'docz-theme-default' import { imports } from './imports' import db from './db.json'  const Root = () => (<theme db="{db}" imports="{imports}" hashrouter="{" false }   >) export default hot(module)(Root)
    |                           ^
    at t (/app/node_modules/docz-utils/node_modules/prettier/parser-babylon.js:1:326)
    at Object.d [as parse] (/app/node_modules/docz-utils/node_modules/prettier/parser-babylon.js:1:187968)
    at Object.parse$2 [as parse] (/app/node_modules/docz-utils/node_modules/prettier/index.js:7138:19)
    at coreFormat (/app/node_modules/docz-utils/node_modules/prettier/index.js:10398:23)
    at format (/app/node_modules/docz-utils/node_modules/prettier/index.js:10570:16)
    at formatWithCursor (/app/node_modules/docz-utils/node_modules/prettier/index.js:10582:12)
    at /app/node_modules/docz-utils/node_modules/prettier/index.js:34924:15
    at Object.format (/app/node_modules/docz-utils/node_modules/prettier/index.js:34943:12)
    at Promise (/app/node_modules/docz-utils/lib/index.js:1:4327)
    at new Promise (<anonymous>)
    at Object.format (/app/node_modules/docz-utils/lib/index.js:1:4292)
    at Promise (/app/node_modules/docz-core/dist/index.js:1:87660)
    at new Promise (<anonymous>)
    at touch (/app/node_modules/docz-core/dist/index.js:1:87581)
    at writeAppFiles (/app/node_modules/docz-core/dist/index.js:1:91416)
    at <anonymous>

I've created a repository with the failing build step if you deploy on Heroku here: https://github.com/shortlist-digital/tapestry-lite-docz

(I've since removed our internal library tapestry-lite from the heroku app, and docz build still fails.

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

This is really strange, and only occurs on Heroku containers.

IssueHuntFest bug good first issue

Most helpful comment

I get the exact same error when building on Netlify. I think I've tracked it down to when a NODE_ENV=production env var is present. In fact this fails the build locally too, as well as in Heroku/Netlify containers:

NODE_ENV=production yarn build:docz
✖  fatal     SyntaxError: Unexpected token, expected ";" (1:27)

Feels like a bug somewhere? Setting NODE_ENV to production is common practice when building on services like Heroku.

All 13 comments

I get the exact same error when building on Netlify. I think I've tracked it down to when a NODE_ENV=production env var is present. In fact this fails the build locally too, as well as in Heroku/Netlify containers:

NODE_ENV=production yarn build:docz
✖  fatal     SyntaxError: Unexpected token, expected ";" (1:27)

Feels like a bug somewhere? Setting NODE_ENV to production is common practice when building on services like Heroku.

@jedrichards I wonder if it's a devDependency being stripped out in production environments... I'll have a play around with NODE_ENV=production on.

Philosophically I wonder if @pedronauck thinks of Docz as a "dev tool" more than a production thing.

If anyone else has this issue we've just been called docz build with NODE_ENV=development

Even if the environment is set as PRODUCTION on your server / container / infra, you can still set the NODE_ENV inline just for that specific command:

// Global ENV NODE_ENV=production
$ NODE_ENV=development yarn run docz:build

docz authors please explain why running NODE_ENV=production docz build will fail!!!

Docz authors, thank you for the fantastic tool and all the work you’ve done on it.

I can’t believe it’s free!

When I find some time I’ll try and contribute a fix as a way of saying thanks.

@bingo4508 might even help too

Hi guys, sorry by the too late answer here. So, about the bug, I think that's something related to the OS or some version of Node may be. Because I always use Netlify and this never happened with me. Which version of Node and Docz you're using?

@pedronauck I think this happens consistently when NODE_ENV=production and you docz build. By default NODE_ENV _isn't_ set to production in Netlify, unlike Heroku, which is why it hasn't happened to you.

Someone with Linux available to test and fix this? I think that is something related to art-template package on this file: https://github.com/pedronauck/docz/blob/master/packages/docz-core/src/utils/fs.ts#L3

@issuehuntfest has funded $30.00 to this issue. See it on IssueHunt

@issuehuntfest has funded $30.00 to this issue. See it on IssueHunt

@richardtks has submitted a pull request. See it on IssueHunt

@pedronauck has rewarded $42.00 to @richardtks. See it on IssueHunt

  • :moneybag: Total deposit: $60.00
  • :tada: Repository reward(20%): $12.00
  • :wrench: Service fee(10%): $6.00

Launched on v0.13.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mzedeler picture mzedeler  ·  31Comments

davidtaboas picture davidtaboas  ·  35Comments

pedronauck picture pedronauck  ·  68Comments

ohardy picture ohardy  ·  24Comments

tadeuszwojcik picture tadeuszwojcik  ·  30Comments