Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: spfx project upgrade causes JSON.parse exception #1723

Closed
MarksPoint opened this issue Jul 20, 2020 · 5 comments
Closed

Bug report: spfx project upgrade causes JSON.parse exception #1723

MarksPoint opened this issue Jul 20, 2020 · 5 comments
Assignees
Milestone

Comments

@MarksPoint
Copy link

Description

I was trying to upgrade our 1.10 project to 1.11 using the O365 CLI.
I simply used spfx project upgrade.
I got the following exception and the O365 CLI quit after that:

o365$ spfx project upgrade
readline.js:1086
            throw err;
            ^

SyntaxError: Unexpected token  in JSON at position 0
    at JSON.parse (<anonymous>)
    at manifestFiles.map (/usr/local/lib/node_modules/@pnp/office365-cli/dist/o365/spfx/commands/project/base-project-command.js:126:35)

Looking at the source code in this repo I noticed the expected encoding for the [webpart].manifest.json file is UTF-8, but somehow mine was UTF-8 with BOM. I changed the encoding of the file to UTF-8 and it started working after that.

Not sure if you'd call this a bug, but at least it's for those out there that run into the same error I did.

To fix this exception using VS Code:

  • Open your project in VS Code
  • Open the manifest.json file
  • Look for the actual encoding in the bottom of the window (mine says UTF-8 with BOM)
  • Click it (the encoding)
  • Choose "Save with Encoding" from the Action menu in the top
  • Choose "UTF-8"
  • Re-run spfx project upgrade

Steps to reproduce

To reproduce this, change the encoding of the manifest.json file to UTF-8 with BOM. Then run spfx project upgrade. You should now have the same exception as mentioned above.

Expected result

Either the result should be that the command works fine with different encodings, or it should detect that the encoding is wrong and tell me that I need to change the encoding to UTF-8.

Actual result

The error mentioned above.

Environment

MacOS, running command from bash terminal inside VS Code.

@waldekmastykarz
Copy link
Member

Thanks for reporting! We haven't noticed it earlier, but we should handle it properly nevertheless. Good catch 👍

@rabwill
Copy link
Contributor

rabwill commented Sep 1, 2020

Hey @waldekmastykarz , I can pick this up 🙂 also sense checking here, we should apply the fix anywhere we read a utf8 encoded file and parse it correct?

@waldekmastykarz
Copy link
Member

Correct! Let's start with this one, and create separate issues for other locations to keep the overview

@rabwill
Copy link
Contributor

rabwill commented Sep 1, 2020

Makes sense, thank you

@rabwill rabwill self-assigned this Sep 1, 2020
@waldekmastykarz waldekmastykarz added this to the v3.1 milestone Sep 12, 2020
@waldekmastykarz
Copy link
Member

We have just released a preview version that fixes this issue. Once again thank you for reporting @MarkydeParky 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants