Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

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

Closed
jonsherrard opened this issue Oct 9, 2018 · 13 comments
Labels
bug Something isn't working good first issue Good for newcomers IssueHuntFest Label for Issue Hunt Festival 2018

Comments

@jonsherrard
Copy link

jonsherrard commented Oct 9, 2018

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.

@jonsherrard jonsherrard changed the title Issue with tpl.js files that are copied over, running through prettier and failing Issue with tpl.js files that are copied over, running through prettier and failing on Heroku Oct 9, 2018
@jedrichards
Copy link

jedrichards commented Oct 23, 2018

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.

@jonsherrard
Copy link
Author

@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.

@jonsherrard
Copy link
Author

jonsherrard commented Nov 2, 2018

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

@chialunwu
Copy link

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

@jonsherrard
Copy link
Author

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

@pedronauck
Copy link
Member

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 pedronauck added the question Usage question or clarification request label Nov 7, 2018
@jedrichards
Copy link

jedrichards commented Nov 7, 2018

@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.

@pedronauck pedronauck added bug Something isn't working good first issue Good for newcomers and removed question Usage question or clarification request labels Dec 4, 2018
@pedronauck
Copy link
Member

pedronauck commented Dec 4, 2018

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

@pedronauck pedronauck added the IssueHuntFest Label for Issue Hunt Festival 2018 label Dec 4, 2018
@IssueHuntBot
Copy link

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

1 similar comment
@IssueHuntBot
Copy link

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

@IssueHuntBot
Copy link

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

@IssueHuntBot
Copy link

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

  • 💰 Total deposit: $60.00
  • 🎉 Repository reward(20%): $12.00
  • 🔧 Service fee(10%): $6.00

@pedronauck
Copy link
Member

Launched on v0.13.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers IssueHuntFest Label for Issue Hunt Festival 2018
Projects
None yet
Development

No branches or pull requests

5 participants