Pkg: Can I pack a project that was generated using create-react-app?

Created on 16 Oct 2018  路  8Comments  路  Source: vercel/pkg

Most helpful comment

I have to confirm - code created by "npx create-react-app" fails:

pkg src/index.js
> [email protected]
> Targets not specified. Assuming:
  node10-linux-x64, node10-macos-x64, node10-win-x64
> Error! Unexpected token (7:16)
  F:\node\react-test\src\index.js

All 8 comments

Yep. Tried it yesterday, works fine.

@raelmiu Thank you for the replay.
Did you do anything special?
I added to package.json the index.js file as the bin property and it doesn't work:
Error! Unexpected token (17:2)

Nothing, try running it directly from the CLI just "pkg index.js" or whatever your entry file is called. Unexpected Token error sounds like there's a typo in your package.json

The error indicates that pkg doesn't know how to handle the syntax of a React component.
The line for which it throws an Error is in the index.js file and contains only \

Did you try the other method? Without referencing package.json?
And does it babel-transpile and boot correctly without pkg?

If by other method you mean referencing to index.js, the answer is yes.
Running npm run build works.

I have to confirm - code created by "npx create-react-app" fails:

pkg src/index.js
> [email protected]
> Targets not specified. Assuming:
  node10-linux-x64, node10-macos-x64, node10-win-x64
> Error! Unexpected token (7:16)
  F:\node\react-test\src\index.js

If I understand correctly, index.js in your example is the entry point for your React application, i.e. your front-end code. This is not what you should be specifying as entry point for pkg - instead, as specified in the readme, you should give it a transpiled Node.js file that launches and serves your application.

For example, you could make a small Node.js script using zeit's serve-handler (https://github.com/zeit/serve-handler) to serve the build directory that you get from running yarn build in your create-react-app application and specify that as the entry point for pkg

Was this page helpful?
0 / 5 - 0 ratings